summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorng0 <ng0@n0.is>2019-09-10 16:59:32 +0000
committerng0 <ng0@n0.is>2019-09-10 16:59:32 +0000
commit04b6df21cd281e8cd540139f8d9ae85defc1961c (patch)
tree6357199445df8d5c0c631bc8f10aef838b1f9f1e /src
parent483b0139a218a5f8a8311bda3eb23bcd88f57688 (diff)
remove CYGWIN codeblocks, drop vendored Windows openvpn, drop win32 specific files.
configures and builds okay. testsuite wasn't checked, will be checked. diff including the plibc removal is now around 14370 lines of code less.
Diffstat (limited to 'src')
-rw-r--r--src/arm/Makefile.am4
-rw-r--r--src/ats-tests/Makefile.am4
-rw-r--r--src/ats-tool/Makefile.am10
-rw-r--r--src/ats/Makefile.am4
-rw-r--r--src/auction/Makefile.am4
-rw-r--r--src/block/Makefile.am4
-rw-r--r--src/cadet/Makefile.am6
-rw-r--r--src/consensus/Makefile.am4
-rw-r--r--src/conversation/Makefile.am4
-rw-r--r--src/conversation/gnunet_gst_def.h2
-rw-r--r--src/core/Makefile.am4
-rw-r--r--src/datacache/Makefile.am4
-rw-r--r--src/datastore/Makefile.am4
-rw-r--r--src/dht/Makefile.am3
-rw-r--r--src/dns/Makefile.am4
-rw-r--r--src/exit/Makefile.am19
-rw-r--r--src/exit/gnunet-helper-exit-windows.c1699
-rw-r--r--src/fragmentation/Makefile.am4
-rw-r--r--src/fs/Makefile.am4
-rw-r--r--src/gns/Makefile.am60
-rw-r--r--src/gns/gns-helper-service-w32.conf4
-rw-r--r--src/gns/gnunet-gns-helper-service-w32.c803
-rw-r--r--src/gns/nss/Makefile.am5
-rw-r--r--src/gns/w32nsp-install.c143
-rw-r--r--src/gns/w32nsp-resolve.c464
-rw-r--r--src/gns/w32nsp-uninstall.c31
-rw-r--r--src/gns/w32nsp.c711
-rw-r--r--src/gns/w32nsp.def2
-rw-r--r--src/gnsrecord/Makefile.am4
-rw-r--r--src/hello/Makefile.am4
-rw-r--r--src/identity/Makefile.am4
-rw-r--r--src/include/Makefile.am8
-rw-r--r--src/include/gnunet_common.h30
-rw-r--r--src/include/tap-windows.h81
-rw-r--r--src/include/winproc.h235
-rw-r--r--src/integration-tests/Makefile.am4
-rw-r--r--src/my/Makefile.am4
-rw-r--r--src/mysql/Makefile.am4
-rw-r--r--src/namecache/Makefile.am5
-rw-r--r--src/namestore/Makefile.am5
-rw-r--r--src/nat/Makefile.am9
-rw-r--r--src/nat/gnunet-helper-nat-client-windows.c529
-rw-r--r--src/nat/gnunet-helper-nat-server-windows.c614
-rw-r--r--src/nse/Makefile.am4
-rw-r--r--src/nt/Makefile.am4
-rw-r--r--src/peerinfo-tool/Makefile.am4
-rw-r--r--src/peerinfo/Makefile.am4
-rw-r--r--src/peerstore/Makefile.am4
-rw-r--r--src/pq/Makefile.am4
-rw-r--r--src/pt/Makefile.am18
-rw-r--r--src/pt/test_gnunet_vpn.c3
-rw-r--r--src/reclaim-attribute/Makefile.am4
-rw-r--r--src/reclaim/Makefile.am4
-rw-r--r--src/regex/Makefile.am4
-rw-r--r--src/rest/Makefile.am4
-rw-r--r--src/revocation/Makefile.am4
-rw-r--r--src/rps/Makefile.am4
-rw-r--r--src/scalarproduct/Makefile.am4
-rw-r--r--src/secretsharing/Makefile.am4
-rw-r--r--src/set/Makefile.am4
-rw-r--r--src/sq/Makefile.am4
-rw-r--r--src/statistics/Makefile.am4
-rw-r--r--src/template/Makefile.am4
-rw-r--r--src/testbed-logger/Makefile.am4
-rw-r--r--src/testbed/Makefile.am4
-rw-r--r--src/testbed/gnunet-service-testbed_cpustatus.c117
-rw-r--r--src/testbed/test_testbed_api_testbed_run.c13
-rw-r--r--src/testing/Makefile.am4
-rw-r--r--src/transport/Makefile.am18
-rw-r--r--src/transport/gnunet-helper-transport-bluetooth.c352
-rw-r--r--src/transport/plugin_transport_udp.c15
-rw-r--r--src/transport/plugin_transport_wlan.h7
-rw-r--r--src/transport/tcp_service_legacy.c111
-rw-r--r--src/util/Makefile.am43
-rw-r--r--src/util/disk.c88
-rw-r--r--src/util/dnsstub.c6
-rw-r--r--src/util/gnunet-timeout-w32.c193
-rw-r--r--src/util/network.c866
-rw-r--r--src/util/os_installation.c78
-rw-r--r--src/util/os_network.c29
-rw-r--r--src/util/os_priority.c615
-rw-r--r--src/util/scheduler.c46
-rw-r--r--src/util/service.c110
-rw-r--r--src/util/strings.c35
-rw-r--r--src/util/test_common_logging_runtime_loglevels.c4
-rw-r--r--src/util/test_configuration.c6
-rw-r--r--src/util/test_getopt.c4
-rw-r--r--src/util/test_resolver_api.c5
-rw-r--r--src/util/test_scheduler.c4
-rw-r--r--src/util/test_service.c3
-rw-r--r--src/util/test_strings.c6
-rw-r--r--src/util/w32cat.c154
-rw-r--r--src/util/win.c1365
-rw-r--r--src/util/winproc.c340
-rw-r--r--src/vpn/Makefile.am20
-rw-r--r--src/vpn/gnunet-helper-vpn-windows.c1610
-rw-r--r--src/zonemaster/Makefile.am4
97 files changed, 74 insertions, 11852 deletions
diff --git a/src/arm/Makefile.am b/src/arm/Makefile.am
index b1706a479..28440d857 100644
--- a/src/arm/Makefile.am
+++ b/src/arm/Makefile.am
@@ -8,10 +8,6 @@ libexecdir= $(pkglibdir)/libexec/
pkgcfg_DATA = \
arm.conf
-if MINGW
- WINFLAGS = -Wl,--no-undefined -Wl,--export-all-symbols
-endif
-
if USE_COVERAGE
AM_CFLAGS = --coverage -O0
XLIB = -lgcov
diff --git a/src/ats-tests/Makefile.am b/src/ats-tests/Makefile.am
index 83f9e1b6a..1804a43bf 100644
--- a/src/ats-tests/Makefile.am
+++ b/src/ats-tests/Makefile.am
@@ -5,10 +5,6 @@ pkgcfgdir= $(pkgdatadir)/config.d/
libexecdir= $(pkglibdir)/libexec/
-if MINGW
- WINFLAGS = -Wl,--no-undefined -Wl,--export-all-symbols
-endif
-
if USE_COVERAGE
AM_CFLAGS = -fprofile-arcs -ftest-coverage
endif
diff --git a/src/ats-tool/Makefile.am b/src/ats-tool/Makefile.am
index 55bfe1322..3bb99aa08 100644
--- a/src/ats-tool/Makefile.am
+++ b/src/ats-tool/Makefile.am
@@ -1,23 +1,19 @@
# This Makefile.am is in the public domain
AM_CPPFLAGS = -I$(top_srcdir)/src/include
-if MINGW
- WINFLAGS = -Wl,--no-undefined -Wl,--export-all-symbols
-endif
-
if USE_COVERAGE
AM_CFLAGS = -fprofile-arcs -ftest-coverage
endif
bin_PROGRAMS = \
- gnunet-ats
+ gnunet-ats
gnunet_ats_SOURCES = \
- gnunet-ats.c
+ gnunet-ats.c
gnunet_ats_LDADD = \
$(top_builddir)/src/util/libgnunetutil.la \
$(top_builddir)/src/ats/libgnunetats.la \
$(top_builddir)/src/nt/libgnunetnt.la \
$(top_builddir)/src/transport/libgnunettransport.la \
$(top_builddir)/src/hello/libgnunethello.la \
- $(GN_LIBINTL)
+ $(GN_LIBINTL)
diff --git a/src/ats/Makefile.am b/src/ats/Makefile.am
index ac8a411eb..d7e5b68c7 100644
--- a/src/ats/Makefile.am
+++ b/src/ats/Makefile.am
@@ -10,10 +10,6 @@ libexecdir= $(pkglibdir)/libexec/
pkgcfg_DATA = \
ats.conf
-if MINGW
- WINFLAGS = -Wl,--no-undefined -Wl,--export-all-symbols
-endif
-
if USE_COVERAGE
AM_CFLAGS = -fprofile-arcs -ftest-coverage
endif
diff --git a/src/auction/Makefile.am b/src/auction/Makefile.am
index f86e846e2..0cb5d5a84 100644
--- a/src/auction/Makefile.am
+++ b/src/auction/Makefile.am
@@ -9,10 +9,6 @@ libexecdir = $(pkglibdir)/libexec/
pkgcfg_DATA = \
auction.conf
-if MINGW
- WINFLAGS = -Wl,--no-undefined -Wl,--export-all-symbols
-endif
-
if USE_COVERAGE
AM_CFLAGS = -fprofile-arcs -ftest-coverage
endif
diff --git a/src/block/Makefile.am b/src/block/Makefile.am
index 05df7541d..d769f7d47 100644
--- a/src/block/Makefile.am
+++ b/src/block/Makefile.am
@@ -3,10 +3,6 @@ AM_CPPFLAGS = -I$(top_srcdir)/src/include
plugindir = $(libdir)/gnunet
-if MINGW
- WINFLAGS = -Wl,--no-undefined -Wl,--export-all-symbols
-endif
-
if USE_COVERAGE
AM_CFLAGS = --coverage
endif
diff --git a/src/cadet/Makefile.am b/src/cadet/Makefile.am
index e7d42f60f..cd4beb4b7 100644
--- a/src/cadet/Makefile.am
+++ b/src/cadet/Makefile.am
@@ -1,10 +1,6 @@
# This Makefile.am is in the public domain
AM_CPPFLAGS = -I$(top_srcdir)/src/include
-if MINGW
- WINFLAGS = -Wl,--no-undefined -Wl,--export-all-symbols
-endif
-
if USE_COVERAGE
AM_CFLAGS = --coverage -O0
XLIB = -lgcov
@@ -38,7 +34,7 @@ libgnunetcadet_la_SOURCES = \
cadet_api_get_path.c \
cadet_api_list_peers.c \
cadet_api_list_tunnels.c \
- cadet_api_helper.c
+ cadet_api_helper.c
libgnunetcadet_la_LIBADD = \
$(top_builddir)/src/util/libgnunetutil.la \
$(XLIB) \
diff --git a/src/consensus/Makefile.am b/src/consensus/Makefile.am
index 991e36a95..4ad224aa3 100644
--- a/src/consensus/Makefile.am
+++ b/src/consensus/Makefile.am
@@ -10,10 +10,6 @@ plugindir = $(libdir)/gnunet
pkgcfg_DATA = \
consensus.conf
-if MINGW
- WINFLAGS = -Wl,--no-undefined -Wl,--export-all-symbols
-endif
-
if USE_COVERAGE
AM_CFLAGS = -fprofile-arcs -ftest-coverage
endif
diff --git a/src/conversation/Makefile.am b/src/conversation/Makefile.am
index c329bebf5..dc8283e9b 100644
--- a/src/conversation/Makefile.am
+++ b/src/conversation/Makefile.am
@@ -3,10 +3,6 @@ SUBDIRS = .
plugindir = $(libdir)/gnunet
-if MINGW
- WINFLAGS = -no-undefined -Wl,--export-all-symbols
-endif
-
AM_CPPFLAGS = \
$(GNUNET_CPPFLAGS) \
-I$(top_srcdir)/src/include \
diff --git a/src/conversation/gnunet_gst_def.h b/src/conversation/gnunet_gst_def.h
index 341341f24..5f5910121 100644
--- a/src/conversation/gnunet_gst_def.h
+++ b/src/conversation/gnunet_gst_def.h
@@ -65,14 +65,12 @@
#include <gst/app/gstappsink.h>
// sockets
-#ifndef MINGW
#if HAVE_NETINET_IN_H
#include <netinet/in.h>
#endif
#include <sys/socket.h>
#include <arpa/inet.h>
#include <netdb.h>
-#endif
#include <sys/types.h>
#include <fcntl.h>
diff --git a/src/core/Makefile.am b/src/core/Makefile.am
index 70ec91fbc..902be3599 100644
--- a/src/core/Makefile.am
+++ b/src/core/Makefile.am
@@ -8,10 +8,6 @@ libexecdir= $(pkglibdir)/libexec/
pkgcfg_DATA = \
core.conf
-if MINGW
- WINFLAGS = -Wl,--no-undefined -Wl,--export-all-symbols
-endif
-
if USE_COVERAGE
AM_CFLAGS = --coverage -O0
XLIB = -lgcov
diff --git a/src/datacache/Makefile.am b/src/datacache/Makefile.am
index 898b51563..9fc00bace 100644
--- a/src/datacache/Makefile.am
+++ b/src/datacache/Makefile.am
@@ -8,10 +8,6 @@ pkgcfgdir= $(pkgdatadir)/config.d/
dist_pkgcfg_DATA = \
datacache.conf
-if MINGW
- WINFLAGS = -Wl,--no-undefined -Wl,--export-all-symbols
-endif
-
if USE_COVERAGE
AM_CFLAGS = --coverage -O0
XLIBS = -lgcov
diff --git a/src/datastore/Makefile.am b/src/datastore/Makefile.am
index 240abbc67..ba65143af 100644
--- a/src/datastore/Makefile.am
+++ b/src/datastore/Makefile.am
@@ -10,10 +10,6 @@ libexecdir= $(pkglibdir)/libexec/
pkgcfg_DATA = \
datastore.conf
-if MINGW
- WINFLAGS = -Wl,--no-undefined -Wl,--export-all-symbols
-endif
-
if USE_COVERAGE
AM_CFLAGS = --coverage -O0
XLIBS = -lgcov
diff --git a/src/dht/Makefile.am b/src/dht/Makefile.am
index c52ac93c7..82d76f33c 100644
--- a/src/dht/Makefile.am
+++ b/src/dht/Makefile.am
@@ -1,8 +1,5 @@
# This Makefile.am is in the public domain
AM_CPPFLAGS = -I$(top_srcdir)/src/include
-if MINGW
- WINFLAGS = -Wl,--no-undefined -Wl,--export-all-symbols -lole32 -lshell32 -liconv -lstdc++ -lcomdlg32 -lgdi32
-endif
plugindir = $(libdir)/gnunet
diff --git a/src/dns/Makefile.am b/src/dns/Makefile.am
index ca2685765..33ec8ef85 100644
--- a/src/dns/Makefile.am
+++ b/src/dns/Makefile.am
@@ -1,10 +1,6 @@
# This Makefile.am is in the public domain
AM_CPPFLAGS = -I$(top_srcdir)/src/include
-if MINGW
- WINFLAGS = -Wl,--no-undefined -Wl,--export-all-symbols
-endif
-
if USE_COVERAGE
AM_CFLAGS = --coverage -O0
endif
diff --git a/src/exit/Makefile.am b/src/exit/Makefile.am
index ea4f08c73..b7286349d 100644
--- a/src/exit/Makefile.am
+++ b/src/exit/Makefile.am
@@ -1,11 +1,6 @@
# This Makefile.am is in the public domain
AM_CPPFLAGS = -I$(top_srcdir)/src/include
-if MINGW
- WINFLAGS = -Wl,--no-undefined,--export-all-symbols
- EXITBIN = gnunet-helper-exit
-endif
-
if USE_COVERAGE
AM_CFLAGS = --coverage -O0
endif
@@ -32,20 +27,10 @@ libexec_PROGRAMS = \
gnunet-daemon-exit \
$(EXITBIN)
-if MINGW
- gnunet_helper_exit_LDFLAGS = \
- -no-undefined -Wl,--export-all-symbols
- gnunet_helper_exit_LDADD = \
- -lsetupapi -lnewdev -lshell32 -liconv -lstdc++ \
- -lcomdlg32 -lgdi32 -liphlpapi
+gnunet_helper_exit_SOURCES = \
+ gnunet-helper-exit.c
- gnunet_helper_exit_SOURCES = \
- gnunet-helper-exit-windows.c
-else
- gnunet_helper_exit_SOURCES = \
- gnunet-helper-exit.c
-endif
gnunet_daemon_exit_SOURCES = \
gnunet-daemon-exit.c exit.h
gnunet_daemon_exit_LDADD = \
diff --git a/src/exit/gnunet-helper-exit-windows.c b/src/exit/gnunet-helper-exit-windows.c
deleted file mode 100644
index 0ffd28148..000000000
--- a/src/exit/gnunet-helper-exit-windows.c
+++ /dev/null
@@ -1,1699 +0,0 @@
-/*
- This file is part of GNUnet.
- Copyright (C) 2010, 2012 Christian Grothoff
-
- GNUnet is free software: you can redistribute it and/or modify it
- under the terms of the GNU Affero General Public License as published
- by the Free Software Foundation, either version 3 of the License,
- or (at your option) any later version.
-
- GNUnet is distributed in the hope that it will be useful, but
- WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- Affero General Public License for more details.
-
- You should have received a copy of the GNU Affero General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>.
-
- SPDX-License-Identifier: AGPL3.0-or-later
- */
-/**
- * @file exit/gnunet-helper-exit-windows.c
- * @brief the helper for the EXIT service in win32 builds.
- * Opens a virtual network-interface, sends data received on the if to stdout,
- * sends data received on stdin to the interface
- * @author Christian M. Fuchs
- *
- * The following list of people have reviewed this code and considered
- * it safe since the last modification (if you reviewed it, please
- * have your name added to the list):
- *
- */
-
-#include <stdio.h>
-#include <Winsock2.h>
-#include <windows.h>
-#include <setupapi.h>
-#ifndef __MINGW64_VERSION_MAJOR
-#include <ddk/cfgmgr32.h>
-#include <ddk/newdev.h>
-#else
-#include <cfgmgr32.h>
-#include <newdev.h>
-#endif
-#include <time.h>
-#include "platform.h"
-#include "tap-windows.h"
-/**
- * Need 'struct GNUNET_HashCode' and 'struct GNUNET_PeerIdentity'.
- */
-#include "gnunet_crypto_lib.h"
-/**
- * Need 'struct GNUNET_MessageHeader'.
- */
-#include "gnunet_common.h"
-
-/**
- * Need VPN message types.
- */
-#include "gnunet_protocols.h"
-
-/**
- * Should we print (interesting|debug) messages that can happen during
- * normal operation?
- */
-#define DEBUG GNUNET_NO
-
-#if DEBUG
-/* FIXME: define with varargs... */
-#define LOG_DEBUG(msg) fprintf(stderr, "%s", msg);
-#else
-#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_MAX_MESSAGE_SIZE)
- */
-#define MAX_SIZE 65536
-
-/**
- * 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/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/openvpn-tap32/tapw64/OemWin2k.inf"
-
-/**
- * Hardware ID used in the inf-file.
- * This might change over time, as openvpn advances their driver
- */
-#define HARDWARE_ID "tap0901"
-
-/**
- * Minimum major-id of the driver version we can work with
- */
-#define TAP_WIN_MIN_MAJOR 9
-
-/**
- * Minimum minor-id of the driver version we can work with.
- * v <= 7 has buggy IPv6.
- * v == 8 is broken for small IPv4 Packets
- */
-#define TAP_WIN_MIN_MINOR 9
-
-/**
- * Time in seconds to wait for our virtual device to go up after telling it to do so.
- *
- * openvpn doesn't specify a value, 4 seems sane for testing, even for openwrt
- * (in fact, 4 was chosen by a fair dice roll...)
- */
-#define TAP32_POSTUP_WAITTIME 4
-
-/**
- * Location of the network interface list resides in registry.
- */
-#define INTERFACE_REGISTRY_LOCATION "SYSTEM\\CurrentControlSet\\Control\\Network\\{4D36E972-E325-11CE-BFC1-08002BE10318}"
-
-/**
- * Our local process' PID. Used for creating a sufficiently unique additional
- * hardware ID for our device.
- */
-static char secondary_hwid[LINE_LEN / 2];
-
-/**
- * Device's visible Name, used to identify a network device in netsh.
- * eg: "Local Area Connection 9"
- */
-static char device_visible_name[256];
-
-/**
- * This is our own local instance of a virtual network interface
- * It is (somewhat) equivalent to using tun/tap in unixoid systems
- *
- * Upon initialization, we create such an device node.
- * Upon termination, we remove it again.
- *
- * If we crash this device might stay around.
- */
-static HDEVINFO DeviceInfo = INVALID_HANDLE_VALUE;
-
-/**
- * Registry Key we hand over to windows to spawn a new virtual interface
- */
-static SP_DEVINFO_DATA DeviceNode;
-
-/**
- * GUID of our virtual device in the form of
- * {12345678-1234-1234-1234-123456789abc} - in hex
- */
-static char device_guid[256];
-
-
-/**
- * Possible states of an IO facility.
- */
-enum IO_State {
- /**
- * overlapped I/O is ready for work
- */
- IOSTATE_READY = 0,
-
- /**
- * overlapped I/O has been queued
- */
- IOSTATE_QUEUED,
-
- /**
- * overlapped I/O has finished, but is waiting for it's write-partner
- */
- IOSTATE_WAITING,
-
- /**
- * there is a full buffer waiting
- */
- IOSTATE_RESUME,
-
- /**
- * Operlapped IO states for facility objects
- * overlapped I/O has failed, stop processing
- */
- IOSTATE_FAILED
-};
-
-
-/**
- * A IO Object + read/writebuffer + buffer-size for windows asynchronous IO handling
- */
-struct io_facility {
- /**
- * The mode the state machine associated with this object is in.
- */
- enum IO_State facility_state;
-
- /**
- * If the path is open or blocked in general (used for quickly checking)
- */
- BOOL path_open; // BOOL is winbool (int), NOT boolean (unsigned char)!
-
- /**
- * Windows Object-Handle (used for accessing TAP and STDIN/STDOUT)
- */
- HANDLE handle;
-
- /**
- * Overlaped IO structure used for asynchronous IO in windows.
- */
- OVERLAPPED overlapped;
-
- /**
- * Buffer for reading things to and writing from...
- */
- unsigned char buffer[MAX_SIZE];
-
- /**
- * How much of this buffer was used when reading or how much data can be written
- */
- DWORD buffer_size;
-
- /**
- * Amount of data actually written or read by readfile/writefile.
- */
- DWORD buffer_size_processed;
-
- /**
- * How much of this buffer we have written in total
- */
- DWORD buffer_size_written;
-};
-
-/**
- * ReOpenFile is only available as of XP SP2 and 2003 SP1
- */
-WINBASEAPI HANDLE WINAPI ReOpenFile(HANDLE, DWORD, DWORD, DWORD);
-
-/**
- * IsWow64Process definition for our is_win64, as this is a kernel function
- */
-typedef BOOL (WINAPI *LPFN_ISWOW64PROCESS)(HANDLE, PBOOL);
-
-
-/**
- * Like strlcpy but portable. The given string @a src is copied until its null
- * byte or until @a n - 1 bytes have been read. The destination buffer is
- * guaranteed to be null-terminated.
- *
- * @param dst destination of the copy (must be @a n bytes long)
- * @param src source of the copy (at most @a n - 1 bytes will be read)
- * @param n the length of the string to copy, including its terminating null
- * byte
- * @return the length of the string that was copied, excluding the terminating
- * null byte
- */
-size_t
-GNUNET_strlcpy(char *dst, const char *src, size_t n)
-{
- size_t ret;
- size_t slen;
-
- GNUNET_assert(0 != n);
- slen = strnlen(src, n - 1);
- memcpy(dst, src, slen);
- dst[slen] = '\0';
- return slen;
-}
-
-
-/**
- * Determines if the host OS is win32 or win64
- *
- * @return true if
- */
-BOOL
-is_win64()
-{
-#if defined(_WIN64)
- //this is a win64 binary,
- return TRUE;
-#elif defined(_WIN32)
- //this is a 32bit binary, and we need to check if we are running in WOW64
- BOOL success = FALSE;
- BOOL on_wow64 = FALSE;
- LPFN_ISWOW64PROCESS IsWow64Process = (LPFN_ISWOW64PROCESS)GetProcAddress(GetModuleHandle("kernel32"), "IsWow64Process");
-
- if (NULL != IsWow64Process)
- success = IsWow64Process(GetCurrentProcess(), &on_wow64);
-
- return success && on_wow64;
-#endif
-}
-/**
- * Wrapper for executing a shellcommand in windows.
- *
- * @param command - the command + parameters to execute
- * @return * exitcode of the program executed,
- * * EINVAL (cmd/file not found)
- * * EPIPE (could not read STDOUT)
- */
-static int
-execute_shellcommand(const char *command)
-{
- FILE *pipe;
-
- if ((NULL == command) ||
- (NULL == (pipe = _popen(command, "rt"))))
- return EINVAL;
-
-#if DEBUG
- fprintf(stderr, "DEBUG: Command output: \n");
- char output[LINE_LEN];
- while (NULL != fgets(output, sizeof(output), pipe))
- fprintf(stderr, "%s", output);
-#endif
-
- return _pclose(pipe);
-}
-
-
-/**
- * @brief Sets the IPv6-Address given in address on the interface dev
- *
- * @param address the IPv6-Address
- * @param prefix_len the length of the network-prefix
- */
-static int
-set_address6(const char *address, unsigned long prefix_len)
-{
- int ret = EINVAL;
- char command[LINE_LEN];
- struct sockaddr_in6 sa6;
-
- /*
- * parse the new address
- */
- memset(&sa6, 0, sizeof(struct sockaddr_in6));
- sa6.sin6_family = AF_INET6;
- if (1 != inet_pton(AF_INET6, address, &sa6.sin6_addr.s6_addr))
- {
- fprintf(stderr, "ERROR: Failed to parse address `%s': %s\n", address,
- strerror(errno));
- return -1;
- }
-
- /*
- * prepare the command
- */
- snprintf(command, LINE_LEN,
- "netsh interface ipv6 add address \"%s\" %s/%d store=active",
- device_visible_name, address, prefix_len);
- /*
- * Set the address
- */
- ret = execute_shellcommand(command);
-
- /* Did it work?*/
- if (0 != ret)
- fprintf(stderr, "FATAL: Setting IPv6 address failed: %s\n", strerror(ret));
- return ret;
-}
-
-
-/**
- * @brief Removes the IPv6-Address given in address from the interface dev
- *
- * @param address the IPv4-Address
- */
-static void
-remove_address6(const char *address)
-{
- char command[LINE_LEN];
- int ret = EINVAL;
-
- // sanity checking was already done in set_address6
- /*
- * prepare the command
- */
- snprintf(command, LINE_LEN,
- "netsh interface ipv6 delete address \"%s\" store=persistent",
- device_visible_name);
- /*
- * Set the address
- */
- ret = execute_shellcommand(command);
-
- /* Did it work?*/
- if (0 != ret)
- fprintf(stderr, "FATAL: removing IPv6 address failed: %s\n", strerror(ret));
-}
-
-
-/**
- * @brief Sets the IPv4-Address given in address on the interface dev
- *
- * @param address the IPv4-Address
- * @param mask the netmask
- */
-static int
-set_address4(const char *address, const char *mask)
-{
- int ret = EINVAL;
- char command[LINE_LEN];
-
- struct sockaddr_in addr;
-
- addr.sin_family = AF_INET;
-
- /*
- * Parse the address
- */
- if (1 != inet_pton(AF_INET, address, &addr.sin_addr.s_addr))
- {
- fprintf(stderr, "ERROR: Failed to parse address `%s': %s\n", address,
- strerror(errno));
- return -1;
- }
- // Set Device to Subnet-Mode?
- // do we really need tun.c:2925 ?
-
- /*
- * prepare the command
- */
- snprintf(command, LINE_LEN,
- "netsh interface ipv4 add address \"%s\" %s %s store=active",
- device_visible_name, address, mask);
- /*
- * Set the address
- */
- ret = execute_shellcommand(command);
-
- /* Did it work?*/
- if (0 != ret)
- fprintf(stderr, "FATAL: Setting IPv4 address failed: %s\n", strerror(ret));
- return ret;
-}
-
-
-/**
- * @brief Removes the IPv4-Address given in address from the interface dev
- *
- * @param address the IPv4-Address
- */
-static void
-remove_address4(const char *address)
-{
- char command[LINE_LEN];
- int ret = EINVAL;
-
- // sanity checking was already done in set_address4
-
- /*
- * prepare the command
- */
- snprintf(command, LINE_LEN,
- "netsh interface ipv4 delete address \"%s\" gateway=all store=persistent",
- device_visible_name);
- /*
- * Set the address
- */
- ret = execute_shellcommand(command);
-
- /* Did it work?*/
- if (0 != ret)
- fprintf(stderr, "FATAL: removing IPv4 address failed: %s\n", strerror(ret));
-}
-
-
-/**
- * Setup a new virtual interface to use for tunneling.
- *
- * @return: TRUE if setup was successful, else FALSE
- */
-static BOOL
-setup_interface()
-{
- /*
- * where to find our inf-file. (+ the "full" path, after windows found")
- *
- * We do not directly input all the props here, because openvpn will update
- * these details over time.
- */
- char inf_file_path[MAX_PATH];
- char * temp_inf_filename;
- char hwidlist[LINE_LEN + 4];
- char class_name[128];
- GUID class_guid;
- int str_length = 0;
-
- /**
- * Set the device's hardware ID and add it to a list.
- * This information will later on identify this device in registry.
- */
- str_length = GNUNET_strlcpy(hwidlist,
- HARDWARE_ID,
- sizeof(hwidlist)) + 1;
- /**
- * this is kind of over-complicated, but allows keeps things independent of
- * how the openvpn-hwid is actually stored.
- *
- * A HWID list is double-\0 terminated and \0 separated
- */
- str_length = strlen(hwidlist) + 1;
- str_length += GNUNET_strlcpy(&hwidlist[str_length],
- secondary_hwid,
- sizeof(hwidlist) - str_length) + 1;
- GNUNET_assert(str_length < sizeof(hwidlist));
- hwidlist[str_length] = '\0';
- ++str_length;
-
- /**
- * Locate the inf-file, we need to store it somewhere where the system can
- * find it. We need to pick the correct driver for win32/win64.
- */
- if (is_win64())
- GetFullPathNameA(INF_FILE64, MAX_PATH, inf_file_path, &temp_inf_filename);
- else
- GetFullPathNameA(INF_FILE, MAX_PATH, inf_file_path, &temp_inf_filename);
-
- fprintf(stderr, "INFO: Located our driver's .inf file at %s\n", inf_file_path);
- /**
- * Bootstrap our device info using the drivers inf-file
- */
- if (!SetupDiGetINFClassA(inf_file_path,
- &class_guid,
- class_name, sizeof(class_name) / sizeof(char),
- NULL))
- return FALSE;
-
- /**
- * Collect all the other needed information...
- * let the system fill our this form
- */
- DeviceInfo = SetupDiCreateDeviceInfoList(&class_guid, NULL);
- if (DeviceInfo == INVALID_HANDLE_VALUE)
- return FALSE;
-
- DeviceNode.cbSize = sizeof(SP_DEVINFO_DATA);
- if (!SetupDiCreateDeviceInfoA(DeviceInfo,
- class_name,
- &class_guid,
- NULL,
- 0,
- DICD_GENERATE_ID,
- &DeviceNode))
- return FALSE;
-
- /* Deploy all the information collected into the registry */
- if (!SetupDiSetDeviceRegistryPropertyA(DeviceInfo,
- &DeviceNode,
- SPDRP_HARDWAREID,
- (LPBYTE)hwidlist,
- str_length * sizeof(char)))
- return FALSE;
-
- /* Install our new class(=device) into the system */
- if (!SetupDiCallClassInstaller(DIF_REGISTERDEVICE,
- DeviceInfo,
- &DeviceNode))
- return FALSE;
-
- /* This system call tends to take a while (several seconds!) on
- "modern" Windoze systems */
- if (!UpdateDriverForPlugAndPlayDevicesA(NULL,
- secondary_hwid,
- inf_file_path,
- INSTALLFLAG_FORCE | INSTALLFLAG_NONINTERACTIVE,
- NULL)) //reboot required? NEVER!
- return FALSE;
-
- fprintf(stderr, "DEBUG: successfully created a network device\n");
- return TRUE;
-}
-
-
-/**
- * Remove our new virtual interface to use for tunneling.
- * This function must be called AFTER setup_interface!
- *
- * @return: TRUE if destruction was successful, else FALSE
- */
-static BOOL
-remove_interface()
-{
- SP_REMOVEDEVICE_PARAMS remove;
-
- if (INVALID_HANDLE_VALUE == DeviceInfo)
- return FALSE;
-
- remove.ClassInstallHeader.cbSize = sizeof(SP_CLASSINSTALL_HEADER);
- remove.HwProfile = 0;
- remove.Scope = DI_REMOVEDEVICE_GLOBAL;
- remove.ClassInstallHeader.InstallFunction = DIF_REMOVE;
- /*
- * 1. Prepare our existing device information set, and place the
- * uninstall related information into the structure
- */
- if (!SetupDiSetClassInstallParamsA(DeviceInfo,
- (PSP_DEVINFO_DATA)&DeviceNode,
- &remove.ClassInstallHeader,
- sizeof(remove)))
- return FALSE;
- /*
- * 2. Uninstall the virtual interface using the class installer
- */
- if (!SetupDiCallClassInstaller(DIF_REMOVE,
- DeviceInfo,
- (PSP_DEVINFO_DATA)&DeviceNode))
- return FALSE;
-
- SetupDiDestroyDeviceInfoList(DeviceInfo);
-
- fprintf(stderr, "DEBUG: removed interface successfully\n");
-
- return TRUE;
-}
-
-
-/**
- * Do all the lookup necessary to retrieve the inteface's actual name
- * off the registry.
- *
- * @return: TRUE if we were able to lookup the interface's name, else FALSE
- */
-static BOOL
-resolve_interface_name()
-{
- SP_DEVINFO_LIST_DETAIL_DATA device_details;
- char pnp_instance_id [MAX_DEVICE_ID_LEN];
- HKEY adapter_key_handle;
- LONG status;
- DWORD len;
- int i = 0;
- int retrys;
- BOOL retval = FALSE;
- char adapter[] = INTERFACE_REGISTRY_LOCATION;
-
- /* We can obtain the PNP instance ID from our setupapi handle */
- device_details.cbSize = sizeof(device_details);
- if (CR_SUCCESS != CM_Get_Device_ID_ExA(DeviceNode.DevInst,
- (PCHAR)pnp_instance_id,
- MAX_DEVICE_ID_LEN,
- 0, //must be 0
- NULL)) //hMachine, we are local
- return FALSE;
-
- fprintf(stderr, "DEBUG: Resolving interface name for network device %s\n", pnp_instance_id);
-
- /* Registry is incredibly slow, retry for up to 30 seconds to allow registry to refresh */
- for (retrys = 0; retrys < 120 && !retval; retrys++)
- {
- /* sleep for 250ms*/
- Sleep(250);
-
- /* Now we can use this ID to locate the correct networks interface in registry */
- if (ERROR_SUCCESS != RegOpenKeyExA(
- HKEY_LOCAL_MACHINE,
- adapter,
- 0,
- KEY_READ,
- &adapter_key_handle))
- return FALSE;
-
- /* Of course there is a multitude of entries here, with arbitrary names,
- * thus we need to iterate through there.
- */
- while (!retval)
- {
- char instance_key[256];
- char query_key [256];
- HKEY instance_key_handle;
- char pnpinstanceid_name[] = "PnpInstanceID";
- char pnpinstanceid_value[256];
- char adaptername_name[] = "Name";
- DWORD data_type;
-
- len = 256 * sizeof(char);
- /* optain a subkey of {4D36E972-E325-11CE-BFC1-08002BE10318} */
- status = RegEnumKeyExA(
- adapter_key_handle,
- i,
- instance_key,
- &len,
- NULL,
- NULL,
- NULL,
- NULL);
-
- /* this may fail due to one of two reasons:
- * we are at the end of the list*/
- if (ERROR_NO_MORE_ITEMS == status)
- break;
- // * we found a broken registry key, continue with the next key.
- if (ERROR_SUCCESS != status)
- goto cleanup;
-
- /* prepare our new query string: */
- snprintf(query_key, 256, "%s\\%s\\Connection",
- adapter,
- instance_key);
-
- /* look inside instance_key\\Connection */
- if (ERROR_SUCCESS != RegOpenKeyExA(
- HKEY_LOCAL_MACHINE,
- query_key,
- 0,
- KEY_READ,
- &instance_key_handle))
- goto cleanup;
-
- /* now, read our PnpInstanceID */
- len = sizeof(pnpinstanceid_value);
- status = RegQueryValueExA(instance_key_handle,
- pnpinstanceid_name,
- NULL, //reserved, always NULL according to MSDN
- &data_type,
- (LPBYTE)pnpinstanceid_value,
- &len);
-
- if (status != ERROR_SUCCESS || data_type != REG_SZ)
- goto cleanup;
-
- /* compare the value we got to our devices PNPInstanceID*/
- if (0 != strncmp(pnpinstanceid_value, pnp_instance_id,
- sizeof(pnpinstanceid_value) / sizeof(char)))
- goto cleanup;
-
- len = sizeof(device_visible_name);
- status = RegQueryValueExA(
- instance_key_handle,
- adaptername_name,
- NULL, //reserved, always NULL according to MSDN
- &data_type,
- (LPBYTE)device_visible_name,
- &len);
-
- if (status != ERROR_SUCCESS || data_type != REG_SZ)
- goto cleanup;
-
- /*
- * we have successfully found OUR instance,
- * save the device GUID before exiting
- */
- GNUNET_strlcpy(device_guid, instance_key, sizeof(device_guid));
- retval = TRUE;
- fprintf(stderr, "DEBUG: Interface Name lookup succeeded on retry %d, got \"%s\" %s\n", retrys, device_visible_name, device_guid);
-
-cleanup:
- RegCloseKey(instance_key_handle);
-
- ++i;
- }
-
- RegCloseKey(adapter_key_handle);
- }
- return retval;
-}
-
-
-/**
- * Determines the version of the installed TAP32 driver and checks if it's sufficiently new for GNUNET
- *
- * @param handle the handle to our tap device
- * @return TRUE if the version is sufficient, else FALSE
- */
-static BOOL
-check_tapw32_version(HANDLE handle)
-{
- ULONG version[3];
- DWORD len;
-
- memset(&(version), 0, sizeof(version));
-
- if (DeviceIoControl(handle, TAP_WIN_IOCTL_GET_VERSION,
- &version, sizeof(version),
- &version, sizeof(version), &len, NULL))
- fprintf(stderr, "INFO: TAP-Windows Driver Version %d.%d %s\n",
- (int)version[0],
- (int)version[1],
- (version[2] ? "(DEBUG)" : ""));
-
- if ((version[0] != TAP_WIN_MIN_MAJOR) ||
- (version[1] < TAP_WIN_MIN_MINOR))
- {
- fprintf(stderr, "FATAL: This version of gnunet requires a TAP-Windows driver that is at least version %d.%d\n",
- TAP_WIN_MIN_MAJOR,
- TAP_WIN_MIN_MINOR);
- return FALSE;
- }
-
- return TRUE;
-}
-
-
-/**
- * Creates a tun-interface called dev;
- *
- * @return the fd to the tun or -1 on error
- */
-static HANDLE
-init_tun()
-{
- char device_path[256];
- HANDLE handle;
-
- if (!setup_interface())
- {
- errno = ENODEV;
- return INVALID_HANDLE_VALUE;
- }
-
- if (!resolve_interface_name())
- {
- errno = ENODEV;
- return INVALID_HANDLE_VALUE;
- }
-
- /* Open Windows TAP-Windows adapter */
- snprintf(device_path, sizeof(device_path), "%s%s%s",
- USERMODEDEVICEDIR,
- device_guid,
- TAP_WIN_SUFFIX);
-
- handle = CreateFile(
- device_path,
- GENERIC_READ | GENERIC_WRITE,
- 0, /* was: FILE_SHARE_READ */
- 0,
- OPEN_EXISTING,
- FILE_ATTRIBUTE_SYSTEM | FILE_FLAG_OVERLAPPED,
- 0
- );
-
- if (INVALID_HANDLE_VALUE == handle)
- {
- fprintf(stderr, "FATAL: CreateFile failed on TAP device: %s\n", device_path);
- return handle;
- }
-
- /* get driver version info */
- if (!check_tapw32_version(handle))
- {
- CloseHandle(handle);
- return INVALID_HANDLE_VALUE;
- }
-
- /* TODO (opt?): get MTU-Size */
-
- fprintf(stderr, "DEBUG: successfully opened TAP device\n");
- return handle;
-}
-
-
-/**
- * Brings a TAP device up and sets it to connected state.
- *
- * @param handle the handle to our TAP device
- * @return True if the operation succeeded, else false
- */
-static BOOL
-tun_up(HANDLE handle)
-{
- ULONG status = TRUE;
- DWORD len;
-
- if (!DeviceIoControl(handle, TAP_WIN_IOCTL_SET_MEDIA_STATUS,
- &status, sizeof(status),
- &status, sizeof(status), &len, NULL))
- {
- fprintf(stderr, "FATAL: TAP driver ignored request to UP interface (DeviceIoControl call)\n");
- return FALSE;
- }
-
- /* Wait for the device to go UP, might take some time. */
- Sleep(TAP32_POSTUP_WAITTIME * 1000);
- fprintf(stderr, "DEBUG: successfully set TAP device to UP\n");
-
- return TRUE;
-}
-
-
-/**
- * Attempts to read off an input facility (tap or named pipe) in overlapped mode.
- *
- * 1.
- * If the input facility is in IOSTATE_READY, it will issue a new read operation to the
- * input handle. Then it goes into IOSTATE_QUEUED state.
- * In case the read succeeded instantly the input facility enters 3.
- *
- * 2.
- * If the input facility is in IOSTATE_QUEUED state, it will check if the queued read has finished already.
- * If it has finished, go to state 3.
- * If it has failed, set IOSTATE_FAILED
- *
- * 3.
- * If the output facility is in state IOSTATE_READY, the read-buffer is copied to the output buffer.
- * The input facility enters state IOSTATE_READY
- * The output facility enters state IOSTATE_READY
- * If the output facility is in state IOSTATE_QUEUED, the input facility enters IOSTATE_WAITING
- *
- * IOSTATE_WAITING is reset by the output facility, once it has completed.
- *
- * @param input_facility input named pipe or file to work with.
- * @param output_facility output pipe or file to hand over data to.
- * @return false if an event reset was impossible (OS error), else true
- */
-static BOOL
-attempt_read_tap(struct io_facility * input_facility,
- struct io_facility * output_facility)
-{
- struct GNUNET_MessageHeader * hdr;
- unsigned short size;
-
- switch (input_facility->facility_state)
- {
- case IOSTATE_READY:
- {
- if (!ResetEvent(input_facility->overlapped.hEvent))
- {
- return FALSE;
- }
-
- input_facility->buffer_size = 0;
-
- /* Check how the task is handled */
- if (ReadFile(input_facility->handle,
- input_facility->buffer,
- sizeof(input_facility->buffer) - sizeof(struct GNUNET_MessageHeader),
- &input_facility->buffer_size,
- &input_facility->overlapped))
- { /* async event processed immediately*/
- /* reset event manually*/
- if (!SetEvent(input_facility->overlapped.hEvent))
- return FALSE;
-
- fprintf(stderr, "DEBUG: tap read succeeded immediately\n");
-
- /* we successfully read something from the TAP and now need to
- * send it our via STDOUT. Is that possible at the moment? */
- if ((IOSTATE_READY == output_facility->facility_state ||
- IOSTATE_WAITING == output_facility->facility_state)
- && (0 < input_facility->buffer_size))
- { /* hand over this buffers content and apply message header for gnunet */
- hdr = (struct GNUNET_MessageHeader *)output_facility->buffer;
- size = input_facility->buffer_size + sizeof(struct GNUNET_MessageHeader);
-
- GNUNET_memcpy(output_facility->buffer + sizeof(struct GNUNET_MessageHeader),
- input_facility->buffer,
- input_facility->buffer_size);
-
- output_facility->buffer_size = size;
- hdr->size = htons(size);
- hdr->type = htons(GNUNET_MESSAGE_TYPE_VPN_HELPER);
- output_facility->facility_state = IOSTATE_READY;
- }
- else if (0 < input_facility->buffer_size)
- /* If we have have read our buffer, wait for our write-partner*/
- input_facility->facility_state = IOSTATE_WAITING;
- }
- else /* operation was either queued or failed*/
- {
- int err = GetLastError();
- if (ERROR_IO_PENDING == err)
- { /* operation queued */
- input_facility->facility_state = IOSTATE_QUEUED;
- }
- else
- { /* error occurred, let the rest of the elements finish */
- input_facility->path_open = FALSE;
- input_facility->facility_state = IOSTATE_FAILED;
- if (IOSTATE_WAITING == output_facility->facility_state)
- output_facility->path_open = FALSE;
-
- fprintf(stderr, "FATAL: Read from handle failed, allowing write to finish\n");
- }
- }
- }
- return TRUE;
-
- // We are queued and should check if the read has finished
- case IOSTATE_QUEUED:
- {
- // there was an operation going on already, check if that has completed now.
-
- if (GetOverlappedResult(input_facility->handle,
- &input_facility->overlapped,
- &input_facility->buffer_size,
- FALSE))
- { /* successful return for a queued operation */
- if (!ResetEvent(input_facility->overlapped.hEvent))
- return FALSE;
-
- fprintf(stderr, "DEBUG: tap read succeeded delayed\n");
-
- /* we successfully read something from the TAP and now need to
- * send it our via STDOUT. Is that possible at the moment? */
- if ((IOSTATE_READY == output_facility->facility_state ||
- IOSTATE_WAITING == output_facility->facility_state)
- && 0 < input_facility->buffer_size)
- { /* hand over this buffers content and apply message header for gnunet */
- hdr = (struct GNUNET_MessageHeader *)output_facility->buffer;
- size = input_facility->buffer_size + sizeof(struct GNUNET_MessageHeader);
-
- GNUNET_memcpy(output_facility->buffer + sizeof(struct GNUNET_MessageHeader),
- input_facility->buffer,
- input_facility->buffer_size);
-
- output_facility->buffer_size = size;
- hdr->size = htons(size);
- hdr->type = htons(GNUNET_MESSAGE_TYPE_VPN_HELPER);
- output_facility->facility_state = IOSTATE_READY;
- input_facility->facility_state = IOSTATE_READY;
- }
- else if (0 < input_facility->buffer_size)
- { /* If we have have read our buffer, wait for our write-partner*/
- input_facility->facility_state = IOSTATE_WAITING;
- // TODO: shall we attempt to fill our buffer or should we wait for our write-partner to finish?
- }
- }
- else
- { /* operation still pending/queued or failed? */
- int err = GetLastError();
- if ((ERROR_IO_INCOMPLETE != err) && (ERROR_IO_PENDING != err))
- { /* error occurred, let the rest of the elements finish */
- input_facility->path_open = FALSE;
- input_facility->facility_state = IOSTATE_FAILED;
- if (IOSTATE_WAITING == output_facility->facility_state)
- output_facility->path_open = FALSE;
- fprintf(stderr, "FATAL: Read from handle failed, allowing write to finish\n");
- }
- }
- }
- return TRUE;
-
- case IOSTATE_RESUME:
- hdr = (struct GNUNET_MessageHeader *)output_facility->buffer;
- size = input_facility->buffer_size + sizeof(struct GNUNET_MessageHeader);
-
- GNUNET_memcpy(output_facility->buffer + sizeof(struct GNUNET_MessageHeader),
- input_facility->buffer,
- input_facility->buffer_size);
-
- output_facility->buffer_size = size;
- hdr->size = htons(size);
- hdr->type = htons(GNUNET_MESSAGE_TYPE_VPN_HELPER);
- output_facility->facility_state = IOSTATE_READY;
- input_facility->facility_state = IOSTATE_READY;
- return TRUE;
-
- default:
- return TRUE;
- }
-}
-
-
-/**
- * Attempts to read off an input facility (tap or named pipe) in overlapped mode.
- *
- * 1.
- * If the input facility is in IOSTATE_READY, it will issue a new read operation to the
- * input handle. Then it goes into IOSTATE_QUEUED state.
- * In case the read succeeded instantly the input facility enters 3.
- *
- * 2.
- * If the input facility is in IOSTATE_QUEUED state, it will check if the queued read has finished already.
- * If it has finished, go to state 3.
- * If it has failed, set IOSTATE_FAILED
- *
- * 3.
- * If the facility is finished with ready
- * The read-buffer is copied to the output buffer, except for the GNUNET_MessageHeader.
- * The input facility enters state IOSTATE_READY
- * The output facility enters state IOSTATE_READY
- * If the output facility is in state IOSTATE_QUEUED, the input facility enters IOSTATE_WAITING
- *
- * IOSTATE_WAITING is reset by the output facility, once it has completed.
- *
- * @param input_facility input named pipe or file to work with.
- * @param output_facility output pipe or file to hand over data to.
- * @return false if an event reset was impossible (OS error), else true
- */
-static BOOL
-attempt_read_stdin(struct io_facility * input_facility,
- struct io_facility * output_facility)
-{
- struct GNUNET_MessageHeader * hdr;
-
- switch (input_facility->facility_state)
- {
- case IOSTATE_READY:
- {
- input_facility->buffer_size = 0;
-
-partial_read_iostate_ready:
- if (!ResetEvent(input_facility->overlapped.hEvent))
- return FALSE;
-
- /* Check how the task is handled */
- if (ReadFile(input_facility->handle,
- input_facility->buffer + input_facility->buffer_size,
- sizeof(input_facility->buffer) - input_facility->buffer_size,
- &input_facility->buffer_size_processed,
- &input_facility->overlapped))
- { /* async event processed immediately*/
- hdr = (struct GNUNET_MessageHeader *)input_facility->buffer;
-
- /* reset event manually*/
- if (!SetEvent(input_facility->overlapped.hEvent))
- return FALSE;
-
- fprintf(stderr, "DEBUG: stdin read succeeded immediately\n");
- input_facility->buffer_size += input_facility->buffer_size_processed;
-
- if (ntohs(hdr->type) != GNUNET_MESSAGE_TYPE_VPN_HELPER ||
- ntohs(hdr->size) > sizeof(input_facility->buffer))
- {
- fprintf(stderr, "WARNING: Protocol violation, got GNUnet Message type %h, size %h\n", ntohs(hdr->type), ntohs(hdr->size));
- input_facility->facility_state = IOSTATE_READY;
- return TRUE;
- }
- /* we got the a part of a packet */
- if (ntohs(hdr->size) > input_facility->buffer_size)
- goto partial_read_iostate_ready;
-
- /* have we read more than 0 bytes of payload? (sizeread > header)*/
- if (input_facility->buffer_size > sizeof(struct GNUNET_MessageHeader) &&
- ((IOSTATE_READY == output_facility->facility_state) ||
- (IOSTATE_WAITING == output_facility->facility_state)))
- { /* we successfully read something from the TAP and now need to
- * send it our via STDOUT. Is that possible at the moment? */
- /* hand over this buffers content and strip gnunet message header */
- GNUNET_memcpy(output_facility->buffer,
- input_facility->buffer + sizeof(struct GNUNET_MessageHeader),
- input_facility->buffer_size - sizeof(struct GNUNET_MessageHeader));
- output_facility->buffer_size = input_facility->buffer_size - sizeof(struct GNUNET_MessageHeader);
- output_facility->facility_state = IOSTATE_READY;
- input_facility->facility_state = IOSTATE_READY;
- }
- else if (input_facility->buffer_size > sizeof(struct GNUNET_MessageHeader))
- /* If we have have read our buffer, wait for our write-partner*/
- input_facility->facility_state = IOSTATE_WAITING;
- else /* we read nothing */
- input_facility->facility_state = IOSTATE_READY;
- }
- else /* operation was either queued or failed*/
- {
- int err = GetLastError();
- if (ERROR_IO_PENDING == err) /* operation queued */
- input_facility->facility_state = IOSTATE_QUEUED;
- else
- { /* error occurred, let the rest of the elements finish */
- input_facility->path_open = FALSE;
- input_facility->facility_state = IOSTATE_FAILED;
- if (IOSTATE_WAITING == output_facility->facility_state)
- output_facility->path_open = FALSE;
-
- fprintf(stderr, "FATAL: Read from handle failed, allowing write to finish\n");
- }
- }
- }
- return TRUE;
-
- // We are queued and should check if the read has finished
- case IOSTATE_QUEUED:
- {
- // there was an operation going on already, check if that has completed now.
- if (GetOverlappedResult(input_facility->handle,
- &input_facility->overlapped,
- &input_facility->buffer_size_processed,
- FALSE))
- { /* successful return for a queued operation */
- hdr = (struct GNUNET_MessageHeader *)input_facility->buffer;
-
- if (!ResetEvent(input_facility->overlapped.hEvent))
- return FALSE;
-
- fprintf(stderr, "DEBUG: stdin read succeeded delayed\n");
- input_facility->buffer_size += input_facility->buffer_size_processed;
-
- if ((ntohs(hdr->type) != GNUNET_MESSAGE_TYPE_VPN_HELPER) ||
- (ntohs(hdr->size) > sizeof(input_facility->buffer)))
- {
- fprintf(stderr, "WARNING: Protocol violation, got GNUnet Message type %h, size %h\n", ntohs(hdr->type), ntohs(hdr->size));
- input_facility->facility_state = IOSTATE_READY;
- return TRUE;
- }
- /* we got the a part of a packet */
- if (ntohs(hdr->size) > input_facility->buffer_size)
- ;
- goto partial_read_iostate_ready;
-
- /* we successfully read something from the TAP and now need to
- * send it our via STDOUT. Is that possible at the moment? */
- if ((IOSTATE_READY == output_facility->facility_state ||
- IOSTATE_WAITING == output_facility->facility_state)
- && input_facility->buffer_size > sizeof(struct GNUNET_MessageHeader))
- { /* hand over this buffers content and strip gnunet message header */
- GNUNET_memcpy(output_facility->buffer,
- input_facility->buffer + sizeof(struct GNUNET_MessageHeader),
- input_facility->buffer_size - sizeof(struct GNUNET_MessageHeader));
- output_facility->buffer_size = input_facility->buffer_size - sizeof(struct GNUNET_MessageHeader);
- output_facility->facility_state = IOSTATE_READY;
- input_facility->facility_state = IOSTATE_READY;
- }
- else if (input_facility->buffer_size > sizeof(struct GNUNET_MessageHeader))
- input_facility->facility_state = IOSTATE_WAITING;
- else
- input_facility->facility_state = IOSTATE_READY;
- }
- else
- { /* operation still pending/queued or failed? */
- int err = GetLastError();
- if ((ERROR_IO_INCOMPLETE != err) && (ERROR_IO_PENDING != err))
- { /* error occurred, let the rest of the elements finish */
- input_facility->path_open = FALSE;
- input_facility->facility_state = IOSTATE_FAILED;
- if (IOSTATE_WAITING == output_facility->facility_state)
- output_facility->path_open = FALSE;
- fprintf(stderr, "FATAL: Read from handle failed, allowing write to finish\n");
- }
- }
- }
- return TRUE;
-
- case IOSTATE_RESUME: /* Our buffer was filled already but our write facility was busy. */
- GNUNET_memcpy(output_facility->buffer,
- input_facility->buffer + sizeof(struct GNUNET_MessageHeader),
- input_facility->buffer_size - sizeof(struct GNUNET_MessageHeader));
- output_facility->buffer_size = input_facility->buffer_size - sizeof(struct GNUNET_MessageHeader);
- output_facility->facility_state = IOSTATE_READY;
- input_facility->facility_state = IOSTATE_READY;
- return TRUE;
-
- default:
- return TRUE;
- }
-}
-
-
-/**
- * Attempts to write to an output facility (tap or named pipe) in overlapped mode.
- *
- * TODO: high level description
- *
- * @param output_facility output pipe or file to hand over data to.
- * @param input_facility input named pipe or file to work with.
- * @return false if an event reset was impossible (OS error), else true
- */
-static BOOL
-attempt_write(struct io_facility * output_facility,
- struct io_facility * input_facility)
-{
- switch (output_facility->facility_state)
- {
- case IOSTATE_READY:
- output_facility->buffer_size_written = 0;
-
-continue_partial_write:
- if (!ResetEvent(output_facility->overlapped.hEvent))
- return FALSE;
-
- /* Check how the task was handled */
- if (WriteFile(output_facility->handle,
- output_facility->buffer + output_facility->buffer_size_written,
- output_facility->buffer_size - output_facility->buffer_size_written,
- &output_facility->buffer_size_processed,
- &output_facility->overlapped))
- {/* async event processed immediately*/
- fprintf(stderr, "DEBUG: write succeeded immediately\n");
- output_facility->buffer_size_written += output_facility->buffer_size_processed;
-
- /* reset event manually*/
- if (!SetEvent(output_facility->overlapped.hEvent))
- return FALSE;
-
- /* partial write */
- if (output_facility->buffer_size_written < output_facility->buffer_size)
- goto continue_partial_write;
-
- /* we are now waiting for our buffer to be filled*/
- output_facility->facility_state = IOSTATE_WAITING;
-
- /* we successfully wrote something and now need to reset our reader */
- if (IOSTATE_WAITING == input_facility->facility_state)
- input_facility->facility_state = IOSTATE_RESUME;
- else if (IOSTATE_FAILED == input_facility->facility_state)
- output_facility->path_open = FALSE;
- }
- else /* operation was either queued or failed*/
- {
- int err = GetLastError();
- if (ERROR_IO_PENDING == err)
- { /* operation queued */
- output_facility->facility_state = IOSTATE_QUEUED;
- }
- else
- { /* error occurred, close this path */
- output_facility->path_open = FALSE;
- output_facility->facility_state = IOSTATE_FAILED;
- fprintf(stderr, "FATAL: Write to handle failed, exiting\n");
- }
- }
- return TRUE;
-
- case IOSTATE_QUEUED:
- // there was an operation going on already, check if that has completed now.
-
- if (GetOverlappedResult(output_facility->handle,
- &output_facility->overlapped,
- &output_facility->buffer_size_processed,
- FALSE))
- {/* successful return for a queued operation */
- if (!ResetEvent(output_facility->overlapped.hEvent))
- return FALSE;
-
- fprintf(stderr, "DEBUG: write succeeded delayed\n");
- output_facility->buffer_size_written += output_facility->buffer_size_processed;
-
- /* partial write */
- if (output_facility->buffer_size_written < output_facility->buffer_size)
- goto continue_partial_write;
-
- /* we are now waiting for our buffer to be filled*/
- output_facility->facility_state = IOSTATE_WAITING;
-
- /* we successfully wrote something and now need to reset our reader */
- if (IOSTATE_WAITING == input_facility->facility_state)
- input_facility->facility_state = IOSTATE_RESUME;
- else if (IOSTATE_FAILED == input_facility->facility_state)
- output_facility->path_open = FALSE;
- }
- else
- { /* operation still pending/queued or failed? */
- int err = GetLastError();
- if ((ERROR_IO_INCOMPLETE != err) && (ERROR_IO_PENDING != err))
- { /* error occurred, close this path */
- output_facility->path_open = FALSE;
- output_facility->facility_state = IOSTATE_FAILED;
- fprintf(stderr, "FATAL: Write to handle failed, exiting\n");
- }
- }
-
- default:
- return TRUE;
- }
-}
-
-
-/**
- * Initialize a overlapped structure
- *
- * @param elem the element to initilize
- * @param initial_state the initial state for this instance
- * @param signaled if the hEvent created should default to signaled or not
- * @return true on success, else false
- */
-static BOOL
-initialize_io_facility(struct io_facility * elem,
- int initial_state,
- BOOL signaled)
-{
- elem->path_open = TRUE;
- elem->handle = INVALID_HANDLE_VALUE;
- elem->facility_state = initial_state;
- elem->buffer_size = 0;
- elem->overlapped.hEvent = CreateEvent(NULL, TRUE, signaled, NULL);
- if (NULL == elem->overlapped.hEvent)
- return FALSE;
-
- return TRUE;
-}
-
-
-/**
- * Start forwarding to and from the tunnel.
- *
- * @param tap_handle device handle for interacting with the Virtual interface
- */
-static void
-run(HANDLE tap_handle)
-{
- /* IO-Facility for reading from our virtual interface */
- struct io_facility tap_read;
- /* IO-Facility for writing to our virtual interface */
- struct io_facility tap_write;
- /* IO-Facility for reading from stdin */
- struct io_facility std_in;
- /* IO-Facility for writing to stdout */
- struct io_facility std_out;
-
- HANDLE parent_std_in_handle = GetStdHandle(STD_INPUT_HANDLE);
- HANDLE parent_std_out_handle = GetStdHandle(STD_OUTPUT_HANDLE);
-
- /* tun up: */
- /* we do this HERE and not beforehand (in init_tun()), in contrast to openvpn
- * to remove the need to flush the arp cache, handle DHCP and wrong IPs.
- *
- * DHCP and such are all features we will never use in gnunet afaik.
- * But for openvpn those are essential.
- */
- if ((privilege_testing) || (!tun_up(tap_handle)))
- goto teardown_final;
-
- /* Initialize our overlapped IO structures*/
- if (!(initialize_io_facility(&tap_read, IOSTATE_READY, FALSE)
- && initialize_io_facility(&tap_write, IOSTATE_WAITING, TRUE)
- && initialize_io_facility(&std_in, IOSTATE_READY, FALSE)
- && initialize_io_facility(&std_out, IOSTATE_WAITING, TRUE)))
- goto teardown_final;
-
- /* Handles for STDIN and STDOUT */
- tap_read.handle = tap_handle;
- tap_write.handle = tap_handle;
-
-#ifdef DEBUG_TO_CONSOLE
- /* Debug output to console STDIN/STDOUT*/
- std_in.handle = parent_std_in_handle;
- std_out.handle = parent_std_out_handle;
-#else
- fprintf(stderr, "DEBUG: reopening stdin/out for overlapped IO\n");
- /*
- * Find out the types of our handles.
- * This part is a problem, because in windows we need to handle files,
- * pipes and the console differently.
- */
- if ((FILE_TYPE_PIPE != GetFileType(parent_std_in_handle)) ||
- (FILE_TYPE_PIPE != GetFileType(parent_std_out_handle)))
- {
- fprintf(stderr, "ERROR: stdin/stdout must be named pipes\n");
- goto teardown;
- }
-
- std_in.handle = ReOpenFile(parent_std_in_handle,
- GENERIC_READ,
- FILE_SHARE_WRITE | FILE_SHARE_READ,
- FILE_FLAG_OVERLAPPED);
-
- if (INVALID_HANDLE_VALUE == std_in.handle)
- {
- fprintf(stderr, "FATAL: Could not reopen stdin for in overlapped mode, has to be a named pipe\n");
- goto teardown;
- }
-
- std_out.handle = ReOpenFile(parent_std_out_handle,
- GENERIC_WRITE,
- FILE_SHARE_READ,
- FILE_FLAG_OVERLAPPED);
-
- if (INVALID_HANDLE_VALUE == std_out.handle)
- {
- fprintf(stderr, "FATAL: Could not reopen stdout for in overlapped mode, has to be a named pipe\n");
- 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 */
- if (std_in.path_open && (!attempt_read_stdin(&std_in, &tap_write)))
- break;
-
- /* perform READ from tap if possible */
- if (tap_read.path_open && (!attempt_read_tap(&tap_read, &std_out)))
- break;
-
- /* perform WRITE to tap if possible */
- if (tap_write.path_open && (!attempt_write(&tap_write, &std_in)))
- break;
-
- /* perform WRITE to STDOUT if possible */
- if (std_out.path_open && (!attempt_write(&std_out, &tap_read)))
- break;
- }
- fprintf(stderr, "DEBUG: teardown initiated\n");
-
-teardown:
-
- CancelIo(tap_handle);
- CancelIo(std_in.handle);
- CancelIo(std_out.handle);
-
-teardown_final:
-
- CloseHandle(tap_handle);
-}
-
-
-/**
- * Open VPN tunnel interface.
- *
- * @param argc must be 6
- * @param argv 0: binary name ("gnunet-helper-exit")
- * 1: tunnel interface name ("gnunet-exit")
- * 2: IPv4 "physical" interface name ("eth0"), or "-" to not do IPv4 NAT
- * 3: IPv6 address ("::1"), or "-" to skip IPv6
- * 4: IPv6 netmask length in bits ("64") [ignored if #4 is "-"]
- * 5: IPv4 address ("1.2.3.4"), or "-" to skip IPv4
- * 6: IPv4 netmask ("255.255.0.0") [ignored if #4 is "-"]
- */
-int
-main(int argc, char **argv)
-{
- char hwid[LINE_LEN];
- HANDLE handle;
- int global_ret = 1;
- int local_ret = EINVAL;
- BOOL have_ip4 = FALSE;
- BOOL have_ip6 = FALSE;
- BOOL have_nat44 = FALSE;
-
- if ((1 < argc) && (0 != strcmp(argv[1], "-d")))
- {
- privilege_testing = TRUE;
- fprintf(stderr,
- "%s",
- "DEBUG: Running binary in privilege testing mode.");
- argv++;
- argc--;
- }
-
- if (6 != argc)
- {
- fprintf(stderr,
- "%s",
- "FATAL: must supply 6 arguments\nUsage:\ngnunet-helper-exit [-d] <if name prefix> <uplink-interface name> <address6 or \"-\"> <netbits6> <address4 or \"-\"> <netmask4>\n");
- return 1;
- }
-
- GNUNET_strlcpy(hwid, argv[1], sizeof(hwid));
-
- /*
- * We use our PID for finding/resolving the control-panel name of our virtual
- * device. PIDs are (of course) unique at runtime, thus we can safely use it
- * as additional hardware-id for our device.
- */
- snprintf(secondary_hwid, LINE_LEN / 2, "%s-%d",
- hwid,
- _getpid());
-
- if (INVALID_HANDLE_VALUE == (handle = init_tun()))
- {
- fprintf(stderr, "FATAL: could not initialize virtual-interface %s with IPv6 %s/%s and IPv4 %s/%s\n",
- hwid,
- argv[3],
- argv[4],
- argv[5],
- argv[6]);
- global_ret = -1;
- goto cleanup;
- }
-
- fprintf(stderr, "DEBUG: Setting IPs, if needed\n");
- if (0 != strcmp(argv[3], "-"))
- {
- char command[LINE_LEN];
- const char *address = argv[3];
- long prefix_len = atol(argv[4]);
-
- if ((prefix_len < 1) || (prefix_len > 127))
- {
- fprintf(stderr, "FATAL: ipv6 prefix_len out of range\n");
- global_ret = -1;
- goto cleanup;
- }
-
- fprintf(stderr, "DEBUG: Setting IP6 address: %s/%d\n", address, prefix_len);
- if (0 != (global_ret = set_address6(address, prefix_len)))
- goto cleanup;
-
- have_ip6 = TRUE;
-
- /* install our the windows NAT module*/
- fprintf(stderr, "DEBUG: Setting IPv6 Forwarding for internal and external interface.\n");
- /* outside interface (maybe that's already set) */
- snprintf(command, LINE_LEN,
- "netsh interface ipv6 set interface interface=\"%s\" metric=1 forwarding=enabled store=active",
- argv[2]);
- local_ret = execute_shellcommand(command);
- if (0 != local_ret)
- {
- fprintf(stderr, "FATAL: Could not enable forwarding via netsh: %s\n", strerror(local_ret));
- goto cleanup;
- }
- /* internal interface */
- snprintf(command, LINE_LEN,
- "netsh interface ipv6 set interface interface=\"%s\" metric=1 forwarding=enabled advertise=enabled store=active",
- device_visible_name);
- local_ret = execute_shellcommand(command);
- if (0 != local_ret)
- {
- fprintf(stderr, "FATAL: Could not enable forwarding via netsh: %s\n", strerror(local_ret));
- goto cleanup;
- }
- /* we can keep IPv6 forwarding around, as all interfaces have
- * their forwarding mode reset to false at bootup. */
- }
-
- if (0 != strcmp(argv[5], "-"))
- {
- const char *address = argv[5];
- const char *mask = argv[6];
-
- fprintf(stderr, "DEBUG: Setting IP4 address: %s/%s\n", address, mask);
- if (0 != (global_ret = set_address4(address, mask)))
- goto cleanup;
-
- // setup NAPT, if possible
- /* MS has REMOVED the routing/nat capabilities from Vista+, thus
- * we can not setup NAT like in XP or on the server. Actually the
- * the only feasible solution seems to be to use
- * Internet Connection Sharing, which introduces a horde of problems
- * such as sending out rogue-RAs on the external interface in an ipv6
- * network.
- * Thus, below stuff ONLY works on
- * WinXP SP3
- * Win Server 2003 SP1+
- * Win Server 2008
- * ...
- */
- have_ip4 = TRUE;
- if (0 != strcmp(argv[2], "-"))
- {
- char command[LINE_LEN];
-
- /* install our the windows NAT module*/
- fprintf(stderr, "DEBUG: Adding NAPT/Masquerading between external IF %s and mine.\n", argv[2]);
- local_ret = execute_shellcommand("netsh routing ip nat install");
- if (0 != local_ret)
- {
- fprintf(stderr, "FATAL: Could not install NAPT support via Netsh: %s\n", strerror(local_ret));
- goto cleanup;
- }
- /* external IF */
- snprintf(command, LINE_LEN,
- "netsh routing ip nat add interface \"%s\" full", /*full = NAPT (addr+port)*/
- argv[2]);
- local_ret = execute_shellcommand(command);
- if (0 != local_ret)
- {
- fprintf(stderr, "FATAL: IPv4-NAPT on external interface failed: %s\n", strerror(local_ret));
- goto cleanup;
- }
- /* private/internal/virtual IF */
- snprintf(command, LINE_LEN,
- "netsh routing ip nat add interface \"%s\" private",
- device_visible_name);
- local_ret = execute_shellcommand(command);
- if (0 != local_ret)
- {
- fprintf(stderr, "FATAL: IPv4-NAPT on internal interface failed: %s\n", strerror(local_ret));
- goto cleanup;
-
- have_nat44 = TRUE;
- }
- }
- }
-
- run(handle);
-cleanup:
-
- if (have_ip4)
- {
- const char *address = argv[5];
- if (have_nat44)
- {
- char command[LINE_LEN];
- fprintf(stderr, "DEBUG: removing IP4 NAPT from virtual interface \n");
- snprintf(command, LINE_LEN,
- "netsh routing ip nat del interface \"%s\"",
- device_visible_name);
- local_ret = execute_shellcommand(command);
- if (0 != local_ret)
- fprintf(stderr, "WARNING: Could not remove IPv4-NAPT from internal interface, hopefully this will have no effect in future runs: %s\n", strerror(local_ret));
- }
-
- fprintf(stderr, "DEBUG: Removing IP4 address\n");
- remove_address4(address);
- }
- if (have_ip6)
- {
- const char *address = argv[3];
- fprintf(stderr, "DEBUG: Removing IP6 address\n");
- remove_address6(address);
- }
-
- fprintf(stderr, "DEBUG: removing interface\n");
- remove_interface();
- fprintf(stderr, "DEBUG: graceful exit completed\n");
-
- return global_ret;
-}
diff --git a/src/fragmentation/Makefile.am b/src/fragmentation/Makefile.am
index 85c4767c0..85df01ff5 100644
--- a/src/fragmentation/Makefile.am
+++ b/src/fragmentation/Makefile.am
@@ -1,10 +1,6 @@
# This Makefile.am is in the public domain
AM_CPPFLAGS = -I$(top_srcdir)/src/include
-if MINGW
- WINFLAGS = -Wl,--no-undefined -Wl,--export-all-symbols
-endif
-
if USE_COVERAGE
AM_CFLAGS = --coverage
endif
diff --git a/src/fs/Makefile.am b/src/fs/Makefile.am
index 80316dc2e..0840242ea 100644
--- a/src/fs/Makefile.am
+++ b/src/fs/Makefile.am
@@ -1,10 +1,6 @@
# This Makefile.am is in the public domain
AM_CPPFLAGS = -I$(top_srcdir)/src/include
-if MINGW
- WINFLAGS = -Wl,--no-undefined -Wl,--export-all-symbols
-endif
-
if USE_COVERAGE
AM_CFLAGS = --coverage -O0
XLIB = -lgcov
diff --git a/src/gns/Makefile.am b/src/gns/Makefile.am
index 0d38cb51e..4a152a6df 100644
--- a/src/gns/Makefile.am
+++ b/src/gns/Makefile.am
@@ -15,7 +15,6 @@ EXTRA_DIST = \
test_gns_lookup.conf \
test_gns_proxy.conf \
test_gns_simple_lookup.conf \
- gns-helper-service-w32.conf \
w32nsp.def \
openssl.cnf \
gnunet-gns-proxy-setup-ca.in \
@@ -25,14 +24,6 @@ EXTRA_DIST = \
$(check_SCRIPTS) \
$(pkgdata_DATA)
-if MINGW
- WINFLAGS = -Wl,--no-undefined -Wl,--export-all-symbols
- DO_W32_HELPER = gnunet-gns-helper-service-w32
- DO_W32_NSP = libw32nsp.la
- DO_W32_NSPTOOLS = w32nsp-install w32nsp-uninstall w32nsp-resolve
- DO_W32_HS_CONF = gns-helper-service-w32.conf
- DO_NONPOSIX_GNSIMPORT = gnunet-gns-import
-endif
USE_VPN = $(top_builddir)/src/vpn/libgnunetvpn.la
if USE_COVERAGE
@@ -46,11 +37,9 @@ libexecdir= $(pkglibdir)/libexec/
plugindir = $(libdir)/gnunet
pkgcfg_DATA = \
- gns.conf \
- $(DO_W32_HS_CONF)
+ gns.conf
lib_LTLIBRARIES = \
- $(DO_W32_NSP) \
libgnunetgns.la
@@ -73,12 +62,9 @@ endif
libexec_PROGRAMS = \
gnunet-service-gns \
gnunet-dns2gns \
- $(DO_W32_HELPER) \
$(DO_PROXY)
bin_PROGRAMS = \
- $(DO_W32_NSPTOOLS) \
- $(DO_NONPOSIX_GNSIMPORT) \
gnunet-gns
noinst_PROGRAMS = \
@@ -199,35 +185,15 @@ test_gns_proxy_LDADD = $(MHD_LIBS) $(LIB_GNURL) -lgnutls \
$(GN_LIBINTL)
test_gns_proxy_CFLAGS = $(MHD_CFLAGS) $(CPP_GNURL) $(AM_CFLAGS)
-gnunet_gns_helper_service_w32_SOURCES = \
- gnunet-gns-helper-service-w32.c
-gnunet_gns_helper_service_w32_LDADD = \
- libgnunetgns.la \
- $(top_builddir)/src/identity/libgnunetidentity.la \
- $(top_builddir)/src/util/libgnunetutil.la \
- $(GN_LIBINTL)
-
-gnunet_gns_import_SOURCES = \
- gnunet-gns-import.c
-gnunet_gns_import_LDADD = \
- $(top_builddir)/src/identity/libgnunetidentity.la \
- $(top_builddir)/src/namestore/libgnunetnamestore.la \
- $(top_builddir)/src/gnsrecord/libgnunetgnsrecord.la \
- $(top_builddir)/src/util/libgnunetutil.la \
- $(GN_LIBINTL)
-
+#gnunet_gns_import_SOURCES = \
+# gnunet-gns-import.c
+#gnunet_gns_import_LDADD = \
+# $(top_builddir)/src/identity/libgnunetidentity.la \
+# $(top_builddir)/src/namestore/libgnunetnamestore.la \
+# $(top_builddir)/src/gnsrecord/libgnunetgnsrecord.la \
+# $(top_builddir)/src/util/libgnunetutil.la \
+# $(GN_LIBINTL)
-w32nsp_install_SOURCES = \
- w32nsp-install.c
-w32nsp_install_LDADD = -lws2_32
-
-w32nsp_uninstall_SOURCES = \
- w32nsp-uninstall.c
-w32nsp_uninstall_LDADD = -lws2_32
-
-w32nsp_resolve_SOURCES = \
- w32nsp-resolve.c
-w32nsp_resolve_LDADD = -lws2_32
gnunet_service_gns_SOURCES = \
gnunet-service-gns.c gnunet-service-gns.h \
@@ -247,14 +213,6 @@ gnunet_service_gns_LDADD = \
$(GN_LIBINTL)
-libw32nsp_la_SOURCES = \
- w32nsp.c
-libw32nsp_la_LIBADD = \
- -lole32 -lws2_32
-libw32nsp_la_LDFLAGS = \
- -export-symbols $(top_srcdir)/src/gns/w32nsp.def \
- -no-undefined -static-libgcc
-
libgnunetgns_la_SOURCES = \
gns_api.c gns_api.h \
gns_tld_api.c gns.h
diff --git a/src/gns/gns-helper-service-w32.conf b/src/gns/gns-helper-service-w32.conf
deleted file mode 100644
index a7b9fdd70..000000000
--- a/src/gns/gns-helper-service-w32.conf
+++ /dev/null
@@ -1,4 +0,0 @@
-[gns-helper-service-w32]
-START_ON_DEMAND = YES
-BINARY = gnunet-gns-helper-service-w32
-PORT = 5353
diff --git a/src/gns/gnunet-gns-helper-service-w32.c b/src/gns/gnunet-gns-helper-service-w32.c
deleted file mode 100644
index 4c4803556..000000000
--- a/src/gns/gnunet-gns-helper-service-w32.c
+++ /dev/null
@@ -1,803 +0,0 @@
-/*
- This file is part of GNUnet.
- Copyright (C) 2012, 2017 GNUnet e.V.
-
- GNUnet is free software: you can redistribute it and/or modify it
- under the terms of the GNU Affero General Public License as published
- by the Free Software Foundation, either version 3 of the License,
- or (at your option) any later version.
-
- GNUnet is distributed in the hope that it will be useful, but
- WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- Affero General Public License for more details.
-
- You should have received a copy of the GNU Affero General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>.
-
- SPDX-License-Identifier: AGPL3.0-or-later
- */
-/**
- * @file gnunet-gns-helper-service-w32.c
- * @brief an intermediary service to access distributed GNS
- * @author Christian Grothoff
- * @author LRN
- */
-#include "platform.h"
-#include <gnunet_util_lib.h>
-#include <gnunet_identity_service.h>
-#include <gnunet_dnsparser_lib.h>
-#include <gnunet_namestore_service.h>
-#include <gnunet_gns_service.h>
-#include <initguid.h>
-#include "gnunet_w32nsp_lib.h"
-#include "w32resolver.h"
-#include <nspapi.h>
-#include <unistr.h>
-
-#define DEFINE_DNS_GUID(a, x) DEFINE_GUID(a, 0x00090035, 0x0000, x, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x46)
-DEFINE_DNS_GUID(SVCID_DNS_TYPE_A, 0x0001);
-DEFINE_DNS_GUID(SVCID_DNS_TYPE_NS, 0x0002);
-DEFINE_DNS_GUID(SVCID_DNS_TYPE_CNAME, 0x0005);
-DEFINE_DNS_GUID(SVCID_DNS_TYPE_SOA, 0x0006);
-DEFINE_DNS_GUID(SVCID_DNS_TYPE_PTR, 0x000c);
-DEFINE_DNS_GUID(SVCID_DNS_TYPE_MX, 0x000f);
-DEFINE_DNS_GUID(SVCID_DNS_TYPE_TEXT, 0x0010);
-DEFINE_DNS_GUID(SVCID_DNS_TYPE_AAAA, 0x001c);
-DEFINE_DNS_GUID(SVCID_DNS_TYPE_SRV, 0x0021);
-DEFINE_GUID(SVCID_HOSTNAME, 0x0002a800, 0x0000, 0x0000, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x46);
-DEFINE_GUID(SVCID_INET_HOSTADDRBYNAME, 0x0002a803, 0x0000, 0x0000, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x46);
-
-
-struct request {
- /**
- * We keep these in a doubly-linked list (for cleanup).
- */
- struct request *next;
-
- /**
- * We keep these in a doubly-linked list (for cleanup).
- */
- struct request *prev;
-
- /**
- * Client that issued the request
- */
- struct GNUNET_SERVICE_Client *client;
-
- GUID sc;
-
- int af;
-
- wchar_t *name;
-
- char *u8name;
-
- struct GNUNET_GNS_LookupRequest *lookup_request;
-};
-
-
-/**
- * Head of the doubly-linked list (for cleanup).
- */
-static struct request *rq_head;
-
-/**
- * Tail of the doubly-linked list (for cleanup).
- */
-static struct request *rq_tail;
-
-/**
- * Handle to GNS service.
- */
-static struct GNUNET_GNS_Handle *gns;
-
-/**
- * Active operation on identity service.
- */
-static struct GNUNET_IDENTITY_Operation *id_op;
-
-/**
- * Handle for identity service.
- */
-static struct GNUNET_IDENTITY_Handle *identity;
-
-/**
- * Public key of the gns-master ego
- */
-static struct GNUNET_CRYPTO_EcdsaPublicKey gns_master_pubkey;
-
-/**
- * Set to 1 once egos are obtained.
- */
-static int got_egos;
-
-
-/**
- * Task run on shutdown. Cleans up everything.
- *
- * @param cls unused
- */
-static void
-do_shutdown(void *cls)
-{
- struct request *rq;
-
- if (NULL != id_op)
- {
- GNUNET_IDENTITY_cancel(id_op);
- id_op = NULL;
- }
- if (NULL != identity)
- {
- GNUNET_IDENTITY_disconnect(identity);
- identity = NULL;
- }
- while (NULL != (rq = rq_head))
- {
- if (NULL != rq->lookup_request)
- GNUNET_GNS_lookup_cancel(rq->lookup_request);
- GNUNET_CONTAINER_DLL_remove(rq_head,
- rq_tail,
- rq);
- GNUNET_free_non_null(rq->name);
- if (rq->u8name)
- free(rq->u8name);
- GNUNET_free(rq);
- }
- if (NULL != gns)
- {
- GNUNET_GNS_disconnect(gns);
- gns = NULL;
- }
-}
-
-
-#define MarshallPtr(ptr, base, type) \
- if (ptr) \
- ptr = (type *) ((char *)ptr - (char *)base)
-
-
-void
-MarshallWSAQUERYSETW(WSAQUERYSETW *qs, GUID *sc)
-{
- MarshallPtr(qs->lpszServiceInstanceName, qs, wchar_t);
- MarshallPtr(qs->lpServiceClassId, qs, GUID);
- MarshallPtr(qs->lpVersion, qs, WSAVERSION);
- MarshallPtr(qs->lpNSProviderId, qs, GUID);
- MarshallPtr(qs->lpszContext, qs, wchar_t);
- MarshallPtr(qs->lpafpProtocols, qs, AFPROTOCOLS);
- MarshallPtr(qs->lpszQueryString, qs, wchar_t);
- for (int i = 0; i < qs->dwNumberOfCsAddrs; i++)
- {
- MarshallPtr(qs->lpcsaBuffer[i].LocalAddr.lpSockaddr, qs, SOCKADDR);
- MarshallPtr(qs->lpcsaBuffer[i].RemoteAddr.lpSockaddr, qs, SOCKADDR);
- }
- MarshallPtr(qs->lpcsaBuffer, qs, CSADDR_INFO);
- if (IsEqualGUID(&SVCID_INET_HOSTADDRBYNAME, sc) && qs->lpBlob != NULL && qs->lpBlob->pBlobData != NULL)
- {
- struct hostent *he;
-
- he = (struct hostent *)qs->lpBlob->pBlobData;
- for (int i = 0; he->h_aliases[i] != NULL; i++)
- MarshallPtr(he->h_aliases[i], he, char);
- MarshallPtr(he->h_aliases, he, char *);
- MarshallPtr(he->h_name, he, char);
- for (int i = 0; he->h_addr_list[i] != NULL; i++)
- MarshallPtr(he->h_addr_list[i], he, void);
- MarshallPtr(he->h_addr_list, he, char *);
- MarshallPtr(qs->lpBlob->pBlobData, qs, void);
- }
- MarshallPtr(qs->lpBlob, qs, BLOB);
-}
-
-
-static void
-process_lookup_result(void *cls,
- uint32_t rd_count,
- const struct GNUNET_GNSRECORD_Data *rd)
-{
- struct request *rq = cls;
- int i, j, csanum;
- struct GNUNET_W32RESOLVER_GetMessage *msg;
- struct GNUNET_MQ_Envelope *msg_env;
- struct GNUNET_MessageHeader *msgend;
- struct GNUNET_MQ_Envelope *msgend_env;
- WSAQUERYSETW *qs;
- size_t size;
- size_t size_recalc;
- char *ptr;
- size_t blobsize = 0;
- size_t blobaddrcount = 0;
-
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
- "Got lookup result with count %u for rq %p with client %p\n",
- rd_count,
- rq,
- rq->client);
- rq->lookup_request = NULL;
-
- if (0 == rd_count)
- {
- msgend_env = GNUNET_MQ_msg(msgend, GNUNET_MESSAGE_TYPE_W32RESOLVER_RESPONSE);
- GNUNET_MQ_send(GNUNET_SERVICE_client_get_mq(rq->client),
- msgend_env);
- GNUNET_CONTAINER_DLL_remove(rq_head,
- rq_tail,
- rq);
- GNUNET_free_non_null(rq->name);
- if (rq->u8name)
- free(rq->u8name);
- GNUNET_free(rq);
- return;
- }
-
- size = sizeof(struct GNUNET_W32RESOLVER_GetMessage) + sizeof(WSAQUERYSETW);
- size += (wcslen(rq->name) + 1) * sizeof(wchar_t);
- size += sizeof(GUID);
- /* lpszComment ? a TXT record? */
- size += sizeof(GUID);
- /* lpszContext ? Not sure what it is */
- csanum = 0;
- for (i = 0; i < rd_count; i++)
- {
- switch (rd[i].record_type)
- {
- case GNUNET_DNSPARSER_TYPE_A:
- if (rd[i].data_size != sizeof(struct in_addr))
- continue;
- size += sizeof(CSADDR_INFO) + sizeof(struct sockaddr_in) * 2;
- csanum++;
- break;
-
- case GNUNET_DNSPARSER_TYPE_AAAA:
- if (rd[i].data_size != sizeof(struct in6_addr))
- continue;
- size += sizeof(CSADDR_INFO) + sizeof(struct sockaddr_in6) * 2;
- csanum++;
- break;
- }
- }
- if (IsEqualGUID(&SVCID_INET_HOSTADDRBYNAME, &rq->sc))
- {
- size += sizeof(BLOB);
- blobsize += sizeof(struct hostent);
- blobsize += strlen(rq->u8name) + 1;
- blobsize += sizeof(void *); /* For aliases */
- blobsize += sizeof(void *); /* For addresses */
- for (i = 0; i < rd_count; i++)
- {
- if ((rq->af == AF_INET || rq->af == AF_UNSPEC) && rd[i].record_type == GNUNET_DNSPARSER_TYPE_A)
- {
- blobsize += sizeof(void *);
- blobsize += sizeof(struct in_addr);
- blobaddrcount++;
- }
- else if (rq->af == AF_INET6 && rd[i].record_type == GNUNET_DNSPARSER_TYPE_AAAA)
- {
- blobsize += sizeof(void *);
- blobsize += sizeof(struct in6_addr);
- blobaddrcount++;
- }
- }
- size += blobsize;
- }
- size_recalc = sizeof(struct GNUNET_W32RESOLVER_GetMessage) + sizeof(WSAQUERYSETW);
- msg_env = GNUNET_MQ_msg_extra(msg,
- size - sizeof(struct GNUNET_MessageHeader),
- GNUNET_MESSAGE_TYPE_W32RESOLVER_RESPONSE);
- msg->af = htonl(rq->af);
- msg->sc_data1 = htonl(rq->sc.Data1);
- msg->sc_data2 = htons(rq->sc.Data2);
- msg->sc_data3 = htons(rq->sc.Data3);
- for (i = 0; i < 8; i++)
- msg->sc_data4[i] = rq->sc.Data4[i];
- qs = (WSAQUERYSETW *)&msg[1];
- ptr = (char *)&qs[1];
- GNUNET_break(size_recalc == (size_t)((char *)ptr - (char *)msg));
- qs->dwSize = sizeof(WSAQUERYSETW);
- qs->lpszServiceInstanceName = (wchar_t *)ptr;
- ptr += (wcslen(rq->name) + 1) * sizeof(wchar_t);
- size_recalc += (wcslen(rq->name) + 1) * sizeof(wchar_t);
- GNUNET_break(size_recalc == (size_t)((char *)ptr - (char *)msg));
- wcscpy(qs->lpszServiceInstanceName, rq->name);
- qs->lpServiceClassId = (GUID *)ptr;
- ptr += sizeof(GUID);
- size_recalc += sizeof(GUID);
- GNUNET_break(size_recalc == (size_t)((char *)ptr - (char *)msg));
- GNUNET_memcpy(qs->lpServiceClassId, &rq->sc, sizeof(GUID));
- qs->lpVersion = NULL;
- qs->dwNameSpace = NS_DNS;
- qs->lpNSProviderId = (GUID *)ptr;
- ptr += sizeof(GUID);
- size_recalc += sizeof(GUID);
- GNUNET_break(size_recalc == (size_t)((char *)ptr - (char *)msg));
- GNUNET_memcpy(qs->lpNSProviderId, &GNUNET_NAMESPACE_PROVIDER_DNS, sizeof(GUID));
- qs->lpszContext = NULL;
- qs->dwNumberOfProtocols = 0;
- qs->lpafpProtocols = NULL;
- /* Don't bother with this... */
- qs->lpszQueryString = NULL;
- qs->dwNumberOfCsAddrs = rd_count;
- qs->lpcsaBuffer = (CSADDR_INFO *)ptr;
- ptr += sizeof(CSADDR_INFO) * csanum;
- j = 0;
- for (i = 0; i < rd_count; i++)
- {
- switch (rd[i].record_type)
- {
- case GNUNET_DNSPARSER_TYPE_A:
- if (rd[i].data_size != sizeof(struct in_addr))
- continue;
- qs->lpcsaBuffer[j].iSocketType = SOCK_STREAM;
- qs->lpcsaBuffer[j].iProtocol = IPPROTO_TCP;
-
- qs->lpcsaBuffer[j].LocalAddr.iSockaddrLength = sizeof(struct sockaddr_in);
- qs->lpcsaBuffer[j].LocalAddr.lpSockaddr = (SOCKADDR *)ptr;
- ptr += qs->lpcsaBuffer[j].LocalAddr.iSockaddrLength;
- memset(qs->lpcsaBuffer[j].LocalAddr.lpSockaddr, 0, qs->lpcsaBuffer[j].LocalAddr.iSockaddrLength);
- ((struct sockaddr_in *)qs->lpcsaBuffer[j].LocalAddr.lpSockaddr)->sin_family = AF_INET;
-
- qs->lpcsaBuffer[j].RemoteAddr.iSockaddrLength = sizeof(struct sockaddr_in);
- qs->lpcsaBuffer[j].RemoteAddr.lpSockaddr = (SOCKADDR *)ptr;
- ptr += qs->lpcsaBuffer[j].RemoteAddr.iSockaddrLength;
- memset(qs->lpcsaBuffer[j].RemoteAddr.lpSockaddr, 0, qs->lpcsaBuffer[j].RemoteAddr.iSockaddrLength);
- ((struct sockaddr_in *)qs->lpcsaBuffer[j].RemoteAddr.lpSockaddr)->sin_family = AF_INET;
- ((struct sockaddr_in *)qs->lpcsaBuffer[j].RemoteAddr.lpSockaddr)->sin_port = htonl(53); /* Don't ask why it's 53 */
- ((struct sockaddr_in *)qs->lpcsaBuffer[j].RemoteAddr.lpSockaddr)->sin_addr = *(struct in_addr *)rd[i].data;
- size_recalc += sizeof(CSADDR_INFO) + sizeof(struct sockaddr_in) * 2;
- j++;
- break;
-
- case GNUNET_DNSPARSER_TYPE_AAAA:
- if (rd[i].data_size != sizeof(struct in6_addr))
- continue;
- qs->lpcsaBuffer[j].iSocketType = SOCK_STREAM;
- qs->lpcsaBuffer[j].iProtocol = IPPROTO_TCP;
-
- qs->lpcsaBuffer[j].LocalAddr.iSockaddrLength = sizeof(struct sockaddr_in6);
- qs->lpcsaBuffer[j].LocalAddr.lpSockaddr = (SOCKADDR *)ptr;
- ptr += qs->lpcsaBuffer[j].LocalAddr.iSockaddrLength;
- memset(qs->lpcsaBuffer[j].LocalAddr.lpSockaddr, 0, qs->lpcsaBuffer[j].LocalAddr.iSockaddrLength);
- ((struct sockaddr_in6 *)qs->lpcsaBuffer[j].LocalAddr.lpSockaddr)->sin6_family = AF_INET6;
-
- qs->lpcsaBuffer[j].RemoteAddr.iSockaddrLength = sizeof(struct sockaddr_in6);
- qs->lpcsaBuffer[j].RemoteAddr.lpSockaddr = (SOCKADDR *)ptr;
- ptr += qs->lpcsaBuffer[j].RemoteAddr.iSockaddrLength;
- memset(qs->lpcsaBuffer[j].RemoteAddr.lpSockaddr, 0, qs->lpcsaBuffer[j].RemoteAddr.iSockaddrLength);
- ((struct sockaddr_in6 *)qs->lpcsaBuffer[j].RemoteAddr.lpSockaddr)->sin6_family = AF_INET6;
- ((struct sockaddr_in6 *)qs->lpcsaBuffer[j].RemoteAddr.lpSockaddr)->sin6_port = htonl(53); /* Don't ask why it's 53 */
- ((struct sockaddr_in6 *)qs->lpcsaBuffer[j].RemoteAddr.lpSockaddr)->sin6_addr = *(struct in6_addr *)rd[i].data;
- size_recalc += sizeof(CSADDR_INFO) + sizeof(struct sockaddr_in6) * 2;
- j++;
- break;
-
- default:
- break;
- }
- }
- GNUNET_break(size_recalc == (size_t)((char *)ptr - (char *)msg));
- qs->dwOutputFlags = 0;
- if (IsEqualGUID(&SVCID_INET_HOSTADDRBYNAME, &rq->sc))
- {
- struct hostent *he;
- qs->lpBlob = (BLOB *)ptr;
- ptr += sizeof(BLOB);
-
- size_recalc += sizeof(BLOB);
- GNUNET_break(size_recalc == (size_t)((char *)ptr - (char *)msg));
-
- qs->lpBlob->cbSize = blobsize;
- qs->lpBlob->pBlobData = (BYTE *)ptr;
- ptr += sizeof(struct hostent);
-
- size_recalc += sizeof(struct hostent);
- GNUNET_break(size_recalc == (size_t)((char *)ptr - (char *)msg));
-
- he = (struct hostent *)qs->lpBlob->pBlobData;
- he->h_name = (char *)ptr;
- ptr += strlen(rq->u8name) + 1;
-
- size_recalc += strlen(rq->u8name) + 1;
- GNUNET_break(size_recalc == (size_t)((char *)ptr - (char *)msg));
-
- strcpy(he->h_name, rq->u8name);
- he->h_aliases = (char **)ptr;
- ptr += sizeof(void *);
-
- size_recalc += sizeof(void *); /* For aliases */
- GNUNET_break(size_recalc == (size_t)((char *)ptr - (char *)msg));
-
- he->h_aliases[0] = NULL;
- he->h_addrtype = rq->af;
- he->h_length = rq->af == AF_INET || rq->af == AF_UNSPEC ? sizeof(struct in_addr) : sizeof(struct in6_addr);
- he->h_addr_list = (char **)ptr;
- ptr += sizeof(void *) * (blobaddrcount + 1);
-
- size_recalc += sizeof(void *) * (blobaddrcount + 1); /* For addresses */
- GNUNET_break(size_recalc == (size_t)((char *)ptr - (char *)msg));
-
- j = 0;
- for (i = 0; i < rd_count; i++)
- {
- if ((rq->af == AF_INET || rq->af == AF_UNSPEC) &&
- rd[i].record_type == GNUNET_DNSPARSER_TYPE_A)
- {
- he->h_addr_list[j] = (char *)ptr;
- ptr += sizeof(struct in_addr);
-
- size_recalc += sizeof(struct in_addr);
- GNUNET_break(size_recalc == (size_t)((char *)ptr - (char *)msg));
-
- GNUNET_memcpy(he->h_addr_list[j], rd[i].data, sizeof(struct in_addr));
- j++;
- }
- else if (rq->af == AF_INET6 && rd[i].record_type == GNUNET_DNSPARSER_TYPE_AAAA)
- {
- he->h_addr_list[j] = (char *)ptr;
- ptr += sizeof(struct in6_addr);
-
- size_recalc += sizeof(struct in6_addr);
- GNUNET_break(size_recalc == (size_t)((char *)ptr - (char *)msg));
-
- GNUNET_memcpy(he->h_addr_list[j], rd[i].data, sizeof(struct in6_addr));
- j++;
- }
- }
- he->h_addr_list[j] = NULL;
- }
- msgend_env = GNUNET_MQ_msg(msgend, GNUNET_MESSAGE_TYPE_W32RESOLVER_RESPONSE);
-
- if ((char *)ptr - (char *)msg != size || size_recalc != size || size_recalc != ((char *)ptr - (char *)msg))
- {
- GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
- "Error in WSAQUERYSETW size calc: expected %u, got %lu (recalc %u)\n",
- size,
- (unsigned long)((char *)ptr - (char *)msg),
- size_recalc);
- }
- MarshallWSAQUERYSETW(qs, &rq->sc);
- GNUNET_MQ_send(GNUNET_SERVICE_client_get_mq(rq->client),
- msg_env);
- GNUNET_MQ_send(GNUNET_SERVICE_client_get_mq(rq->client),
- msgend_env);
- GNUNET_CONTAINER_DLL_remove(rq_head,
- rq_tail,
- rq);
- GNUNET_free_non_null(rq->name);
- if (rq->u8name)
- free(rq->u8name);
- GNUNET_free(rq);
-}
-
-
-static void
-get_ip_from_hostname(struct GNUNET_SERVICE_Client *client,
- const wchar_t *name,
- int af,
- GUID sc)
-{
- struct request *rq;
- char *hostname;
- size_t strl;
- size_t namelen;
- uint32_t rtype;
-
- if (IsEqualGUID(&SVCID_DNS_TYPE_A, &sc))
- rtype = GNUNET_DNSPARSER_TYPE_A;
- else if (IsEqualGUID(&SVCID_DNS_TYPE_NS, &sc))
- rtype = GNUNET_DNSPARSER_TYPE_NS;
- else if (IsEqualGUID(&SVCID_DNS_TYPE_CNAME, &sc))
- rtype = GNUNET_DNSPARSER_TYPE_CNAME;
- else if (IsEqualGUID(&SVCID_DNS_TYPE_SOA, &sc))
- rtype = GNUNET_DNSPARSER_TYPE_SOA;
- else if (IsEqualGUID(&SVCID_DNS_TYPE_PTR, &sc))
- rtype = GNUNET_DNSPARSER_TYPE_PTR;
- else if (IsEqualGUID(&SVCID_DNS_TYPE_MX, &sc))
- rtype = GNUNET_DNSPARSER_TYPE_MX;
- else if (IsEqualGUID(&SVCID_DNS_TYPE_TEXT, &sc))
- rtype = GNUNET_DNSPARSER_TYPE_TXT;
- else if (IsEqualGUID(&SVCID_DNS_TYPE_AAAA, &sc))
- rtype = GNUNET_DNSPARSER_TYPE_AAAA;
- else if (IsEqualGUID(&SVCID_DNS_TYPE_SRV, &sc))
- rtype = GNUNET_DNSPARSER_TYPE_SRV;
- else if (IsEqualGUID(&SVCID_INET_HOSTADDRBYNAME, &sc))
- rtype = GNUNET_DNSPARSER_TYPE_A;
- else
- {
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
- "Unknown GUID: %08lX-%04X-%04X-%02X-%02X-%02X-%02X-%02X-%02X-%02X-%02X\n",
- sc.Data1,
- sc.Data2,
- sc.Data3,
- sc.Data4[0],
- sc.Data4[1],
- sc.Data4[2],
- sc.Data4[3],
- sc.Data4[4],
- sc.Data4[5],
- sc.Data4[6],
- sc.Data4[7]);
- GNUNET_SERVICE_client_drop(client);
- return;
- }
-
- if (name)
- namelen = wcslen(name);
- else
- namelen = 0;
- if (namelen > 0)
- hostname = (char *)u16_to_u8(name, namelen + 1, NULL, &strl);
- else
- hostname = NULL;
-
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
- "W32 DNS resolver asked to look up %s for `%s'.\n",
- af == AF_INET ? "IPv4" : af == AF_INET6 ? "IPv6" : "anything",
- hostname);
-
- rq = GNUNET_new(struct request);
- rq->sc = sc;
- rq->client = client;
- rq->af = af;
- if (rq->af != AF_INET && rq->af != AF_INET6)
- rq->af = AF_INET;
- if (namelen)
- {
- rq->name = GNUNET_malloc((namelen + 1) * sizeof(wchar_t));
- GNUNET_memcpy(rq->name,
- name,
- (namelen + 1) * sizeof(wchar_t));
- rq->u8name = hostname;
- }
-
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
- "Launching a lookup for client %p with rq %p\n",
- client,
- rq);
- rq->lookup_request = GNUNET_GNS_lookup(gns,
- hostname,
- &gns_master_pubkey,
- rtype,
- GNUNET_NO /* Use DHT */,
- &process_lookup_result,
- rq);
- if (NULL != rq->lookup_request)
- {
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
- "Lookup launched, waiting for a reply\n");
- GNUNET_SERVICE_client_continue(client);
- GNUNET_CONTAINER_DLL_insert(rq_head,
- rq_tail,
- rq);
- }
- else
- {
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
- "Lookup was not launched, disconnecting the client\n");
- GNUNET_free_non_null(rq->name);
- if (rq->u8name)
- free(rq->u8name);
- GNUNET_free(rq);
- GNUNET_SERVICE_client_drop(client);
- }
-}
-
-
-/**
- * Check GET-message.
- *
- * @param cls identification of the client
- * @param msg the actual message
- * @return #GNUNET_OK if @a msg is well-formed
- */
-static int
-check_get(void *cls,
- const struct GNUNET_W32RESOLVER_GetMessage *msg)
-{
- uint16_t size;
- const wchar_t *hostname;
-
- if (!got_egos)
- {
- GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
- _("Not ready to process requests, lacking ego data\n"));
- return GNUNET_SYSERR;
- }
- size = ntohs(msg->header.size) - sizeof(struct GNUNET_W32RESOLVER_GetMessage);
- hostname = (const wchar_t *)&msg[1];
- if (hostname[size / 2 - 1] != L'\0')
- {
- GNUNET_break(0);
- return GNUNET_SYSERR;
- }
- return GNUNET_OK;
-}
-
-
-/**
- * Handle GET-message.
- *
- * @param cls identification of the client
- * @param msg the actual message
- */
-static void
-handle_get(void *cls,
- const struct GNUNET_W32RESOLVER_GetMessage *msg)
-{
- struct GNUNET_SERVICE_Client *client = cls;
- GUID sc;
- uint16_t size;
- const wchar_t *hostname;
- int af;
-
- size = ntohs(msg->header.size) - sizeof(struct GNUNET_W32RESOLVER_GetMessage);
- af = ntohl(msg->af);
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
- "Got NBO GUID: %08X-%04X-%04X-%02X-%02X-%02X-%02X-%02X-%02X-%02X-%02X\n",
- msg->sc_data1,
- msg->sc_data2,
- msg->sc_data3,
- msg->sc_data4[0],
- msg->sc_data4[1],
- msg->sc_data4[2],
- msg->sc_data4[3],
- msg->sc_data4[4],
- msg->sc_data4[5],
- msg->sc_data4[6],
- msg->sc_data4[7]);
- sc.Data1 = ntohl(msg->sc_data1);
- sc.Data2 = ntohs(msg->sc_data2);
- sc.Data3 = ntohs(msg->sc_data3);
- for (int i = 0; i < 8; i++)
- sc.Data4[i] = msg->sc_data4[i];
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
- "Got GUID: %08lX-%04X-%04X-%02X-%02X-%02X-%02X-%02X-%02X-%02X-%02X\n",
- sc.Data1,
- sc.Data2,
- sc.Data3,
- sc.Data4[0],
- sc.Data4[1],
- sc.Data4[2],
- sc.Data4[3],
- sc.Data4[4],
- sc.Data4[5],
- sc.Data4[6],
- sc.Data4[7]);
- hostname = (const wchar_t *)&msg[1];
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
- "Name of %u bytes (last word is 0x%0X): %*S\n",
- size,
- hostname[size / 2 - 2],
- size / 2,
- hostname);
- get_ip_from_hostname(client,
- hostname,
- af,
- sc);
-}
-
-
-/**
- * Method called to with the ego we are to use for the lookup,
- * when the ego is the one for the default master zone.
- *
- * @param cls closure (NULL, unused)
- * @param ego ego handle, NULL if not found
- * @param ctx context for application to store data for this ego
- * (during the lifetime of this process, initially NULL)
- * @param name name assigned by the user for this ego,
- * NULL if the user just deleted the ego and it
- * must thus no longer be used
- */
-static void
-identity_master_cb(void *cls,
- struct GNUNET_IDENTITY_Ego *ego,
- void **ctx,
- const char *name)
-{
- id_op = NULL;
- if (NULL == ego)
- {
- GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
- _("Ego for `gns-master' not found, cannot perform lookup. Did you run gnunet-gns-import.sh?\n"));
- GNUNET_SCHEDULER_shutdown();
- return;
- }
- GNUNET_IDENTITY_ego_get_public_key(ego,
- &gns_master_pubkey);
- got_egos = 1;
-}
-
-
-/**
- * Start up gns-helper-w32 service.
- *
- * @param cls closure
- * @param cfg configuration to use
- * @param service the initialized service
- */
-static void
-run(void *cls,
- const struct GNUNET_CONFIGURATION_Handle *cfg,
- struct GNUNET_SERVICE_Handle *service)
-{
- gns = GNUNET_GNS_connect(cfg);
- if (NULL == gns)
- {
- fprintf(stderr,
- _("Failed to connect to GNS\n"));
- GNUNET_SCHEDULER_shutdown();
- return;
- }
- GNUNET_SCHEDULER_add_shutdown(&do_shutdown,
- NULL);
- identity = GNUNET_IDENTITY_connect(cfg,
- NULL,
- NULL);
- if (NULL == identity)
- {
- fprintf(stderr,
- _("Failed to connect to identity service\n"));
- GNUNET_SCHEDULER_shutdown();
- return;
- }
- id_op = GNUNET_IDENTITY_get(identity,
- "gns-master",
- &identity_master_cb,
- NULL);
- GNUNET_assert(NULL != id_op);
-}
-
-
-/**
- * Handle client connecting to the service.
- *
- * @param cls NULL
- * @param client the new client
- * @param mq the message queue of @a client
- * @return @a client
- */
-static void *
-client_connect_cb(void *cls,
- struct GNUNET_SERVICE_Client *client,
- struct GNUNET_MQ_Handle *mq)
-{
- return client;
-}
-
-
-/**
- * Callback called when a client disconnected from the service
- *
- * @param cls closure for the service
- * @param c the client that disconnected
- * @param internal_cls should be equal to @a c
- */
-static void
-client_disconnect_cb(void *cls,
- struct GNUNET_SERVICE_Client *client,
- void *internal_cls)
-{
- GNUNET_assert(internal_cls == client);
-}
-
-
-/**
- * Define "main" method using service macro.
- */
-GNUNET_SERVICE_MAIN
- ("gns-helper-service-w32",
- GNUNET_SERVICE_OPTION_NONE,
- &run,
- &client_connect_cb,
- &client_disconnect_cb,
- NULL,
- GNUNET_MQ_hd_var_size(get,
- GNUNET_MESSAGE_TYPE_W32RESOLVER_REQUEST,
- struct GNUNET_W32RESOLVER_GetMessage,
- NULL),
- GNUNET_MQ_handler_end());
-
-
-/* end of gnunet-gns-helper-service-w32.c */
diff --git a/src/gns/nss/Makefile.am b/src/gns/nss/Makefile.am
index 5d42f777f..f4a12ddee 100644
--- a/src/gns/nss/Makefile.am
+++ b/src/gns/nss/Makefile.am
@@ -18,18 +18,16 @@
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
# USA.
-EXTRA_DIST = map-file
+EXTRA_DIST = map-file
AM_LDFLAGS=-avoid-version -module -export-dynamic
nssdir = $(libdir)/gnunet/nss
-if !MINGW
nss_LTLIBRARIES = \
libnss_gns.la \
libnss_gns4.la \
libnss_gns6.la
-endif
sources = nss_gns_query.h nss_gns_query.c
@@ -45,4 +43,3 @@ libnss_gns4_la_LDFLAGS=$(libnss_gns_la_LDFLAGS)
libnss_gns6_la_SOURCES=$(libnss_gns_la_SOURCES)
libnss_gns6_la_CFLAGS=$(libnss_gns_la_CFLAGS) -DNSS_IPV6_ONLY=1
libnss_gns6_la_LDFLAGS=$(libnss_gns_la_LDFLAGS)
-
diff --git a/src/gns/w32nsp-install.c b/src/gns/w32nsp-install.c
deleted file mode 100644
index 2674359fb..000000000
--- a/src/gns/w32nsp-install.c
+++ /dev/null
@@ -1,143 +0,0 @@
-/*
- This file is part of GNUnet.
- Copyright (C) 2012 GNUnet e.V.
-
- GNUnet is free software: you can redistribute it and/or modify it
- under the terms of the GNU Affero General Public License as published
- by the Free Software Foundation, either version 3 of the License,
- or (at your option) any later version.
-
- GNUnet is distributed in the hope that it will be useful, but
- WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- Affero General Public License for more details.
-
- You should have received a copy of the GNU Affero General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>.
-
- SPDX-License-Identifier: AGPL3.0-or-later
- */
-/**
- * @file gns/w32nsp-install.c
- * @brief W32 integration installer for GNS
- * @author LRN
- */
-
-#include <ws2spi.h>
-#include <windows.h>
-#include <nspapi.h>
-#include <initguid.h>
-#include "gnunet_w32nsp_lib.h"
-#include <stdio.h>
-
-int
-main(int argc, char **argv)
-{
- int ret;
- int r = 1;
- WSADATA wsd;
- GUID id = GNUNET_NAMESPACE_PROVIDER_DNS;
- wchar_t *cmdl;
- int wargc;
- wchar_t **wargv;
- /* Allocate a 4K buffer to retrieve all the namespace providers */
- DWORD dwInitialBufferLen = 4096;
- DWORD dwBufferLen;
- WSANAMESPACE_INFO *pi;
- int p_count;
- int i;
-
- if (WSAStartup(MAKEWORD(2, 2), &wsd) != 0)
- {
- fprintf(stderr, "WSAStartup () failed: %lu\n", GetLastError());
- return 5;
- }
-
- dwBufferLen = dwInitialBufferLen;
- pi = malloc(dwBufferLen);
- if (NULL == pi)
- {
- fprintf(stderr, "malloc (%lu) failed: %d\n", dwBufferLen, errno);
- WSACleanup();
- return 6;
- }
- p_count = WSAEnumNameSpaceProviders(&dwBufferLen, pi);
- if (SOCKET_ERROR == p_count)
- {
- DWORD err = GetLastError();
- if (WSAEFAULT == err && dwBufferLen != dwInitialBufferLen)
- {
- free(pi);
-
- pi = malloc(dwBufferLen);
- if (pi == NULL)
- {
- fprintf(stderr, "malloc (%lu) failed: %d\n", dwBufferLen, errno);
- WSACleanup();
- return 6;
- }
-
- p_count = WSAEnumNameSpaceProviders(&dwBufferLen, pi);
- if (SOCKET_ERROR == p_count)
- {
- fprintf(stderr, "WSAEnumNameSpaceProviders (&%lu, %p) failed: %lu\n", dwBufferLen, pi, GetLastError());
- free(pi);
- WSACleanup();
- return 7;
- }
- }
- else
- {
- fprintf(stderr, "WSAEnumNameSpaceProviders (&%lu, %p) failed: %lu\n", dwBufferLen, pi, GetLastError());
- free(pi);
- WSACleanup();
- return 8;
- }
- }
- for (i = 0; i < p_count; i++)
- {
- if (IsEqualGUID(&pi[i].NSProviderId, &id))
- {
- fprintf(stderr, "GNUnet DNS provider is already installed\n");
- free(pi);
- WSACleanup();
- return 0;
- }
- }
- free(pi);
-
- cmdl = GetCommandLineW();
- if (cmdl == NULL)
- {
- WSACleanup();
- return 2;
- }
- wargv = CommandLineToArgvW(cmdl, &wargc);
- if (wargv == NULL)
- {
- WSACleanup();
- return 3;
- }
- r = 4;
-
- if (wargc == 2)
- {
- ret = WSCInstallNameSpace(L"GNUnet DNS provider", wargv[1], NS_DNS, 0, &id);
- if (ret == NO_ERROR)
- {
- fprintf(stderr, "Installed GNUnet DNS provider\n");
- r = 0;
- }
- else
- {
- r = 1;
- fprintf(stderr,
- "WSCInstallNameSpace (L\"GNUnet DNS provider\", \"%S\", %d, 0, %p) failed: %lu\n",
- wargv[1], NS_DNS, &id, GetLastError());
- }
- }
- else
- fprintf(stderr, "Usage: %S <path-to-libw32nsp>\n", wargv[0]);
- WSACleanup();
- return r;
-}
diff --git a/src/gns/w32nsp-resolve.c b/src/gns/w32nsp-resolve.c
deleted file mode 100644
index ad0fd3586..000000000
--- a/src/gns/w32nsp-resolve.c
+++ /dev/null
@@ -1,464 +0,0 @@
-/*
- This file is part of GNUnet.
- Copyright (C) 2012 GNUnet e.V.
-
- GNUnet is free software: you can redistribute it and/or modify it
- under the terms of the GNU Affero General Public License as published
- by the Free Software Foundation, either version 3 of the License,
- or (at your option) any later version.
-
- GNUnet is distributed in the hope that it will be useful, but
- WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- Affero General Public License for more details.
-
- You should have received a copy of the GNU Affero General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>.
-
- SPDX-License-Identifier: AGPL3.0-or-later
- */
-/**
- * @file gns/w32nsp-resolve.c
- * @brief W32 integration for GNS
- * @author LRN
- */
-/* Instead of including gnunet_common.h */
-#define GNUNET_memcpy(dst, src, n) do { if (0 != n) { (void)memcpy(dst, src, n); } } while (0)
-
-#include <ws2tcpip.h>
-#include <windows.h>
-#include <nspapi.h>
-#include <ws2spi.h>
-#include <nspapi.h>
-#include <initguid.h>
-#include "gnunet_w32nsp_lib.h"
-#include <stdio.h>
-
-typedef int (WSPAPI *LPNSPSTARTUP)(LPGUID lpProviderId, LPNSP_ROUTINE lpnspRoutines);
-
-GUID host = { 0x0002a800, 0, 0, { 0xC0, 0, 0, 0, 0, 0, 0, 0x46 } };
-GUID ip4 = { 0x00090035, 0, 1, { 0xc0, 0, 0, 0, 0, 0, 0, 0x046 } };
-GUID ip6 = { 0x00090035, 0, 0x001c, { 0xc0, 0, 0, 0, 0, 0, 0, 0x046 } };
-
-DEFINE_GUID(W32_DNS, 0x22059D40, 0x7E9E, 0x11CF, 0xAE, 0x5A, 0x00, 0xAA, 0x00, 0xA7, 0x11, 0x2B);
-
-#define DEFINE_DNS_GUID(a, x) DEFINE_GUID(a, 0x00090035, 0x0000, x, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x46)
-DEFINE_DNS_GUID(SVCID_DNS_TYPE_A, 0x0001);
-DEFINE_DNS_GUID(SVCID_DNS_TYPE_NS, 0x0002);
-DEFINE_DNS_GUID(SVCID_DNS_TYPE_CNAME, 0x0005);
-DEFINE_DNS_GUID(SVCID_DNS_TYPE_SOA, 0x0006);
-DEFINE_DNS_GUID(SVCID_DNS_TYPE_PTR, 0x000c);
-DEFINE_DNS_GUID(SVCID_DNS_TYPE_MX, 0x000f);
-DEFINE_DNS_GUID(SVCID_DNS_TYPE_TEXT, 0x0010);
-DEFINE_DNS_GUID(SVCID_DNS_TYPE_AAAA, 0x001c);
-DEFINE_DNS_GUID(SVCID_DNS_TYPE_SRV, 0x0021);
-DEFINE_GUID(SVCID_HOSTNAME, 0x0002a800, 0x0000, 0x0000, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x46);
-DEFINE_GUID(SVCID_INET_HOSTADDRBYNAME, 0x0002a803, 0x0000, 0x0000, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x46);
-
-//
-// Utility to turn a list of offsets into a list of addresses. Used
-// to convert structures returned as BLOBs.
-//
-
-VOID
-FixList(PCHAR ** List, PCHAR Base)
-{
- if (*List)
- {
- PCHAR * Addr;
-
- Addr = *List = (PCHAR *)(((DWORD)*List + Base));
- while (*Addr)
- {
- *Addr = (PCHAR)(((DWORD)*Addr + Base));
- Addr++;
- }
- }
-}
-
-
-//
-// Routine to convert a hostent returned in a BLOB to one with
-// usable pointers. The structure is converted in-place.
-//
-VOID
-UnpackHostEnt(struct hostent * hostent)
-{
- PCHAR pch;
-
- pch = (PCHAR)hostent;
-
- if (hostent->h_name)
- {
- hostent->h_name = (PCHAR)((DWORD)hostent->h_name + pch);
- }
- FixList(&hostent->h_aliases, pch);
- FixList(&hostent->h_addr_list, pch);
-}
-
-
-static void
-print_hostent(struct hostent *he)
-{
- int i;
- char **pAlias;
-
- printf("\tOfficial name: %s\n", he->h_name);
- for (i = 0, pAlias = he->h_aliases; *pAlias != 0; pAlias++)
- {
- printf("\tAlternate name #%d: %s\n", ++i, *pAlias);
- }
- printf("\tAddress type: ");
- switch (he->h_addrtype)
- {
- case AF_INET:
- printf("AF_INET\n");
- break;
-
- case AF_INET6:
- printf("AF_INET6\n");
- break;
-
- case AF_NETBIOS:
- printf("AF_NETBIOS\n");
- break;
-
- default:
- printf(" %d\n", he->h_addrtype);
- break;
- }
- printf("\tAddress length: %d\n", he->h_length);
-
- if (he->h_addrtype == AF_INET)
- {
- struct sockaddr_in addr;
- memset(&addr, 0, sizeof(addr));
- addr.sin_family = AF_INET;
- addr.sin_port = 0;
- i = 0;
- while (he->h_addr_list[i] != 0)
- {
- char buf[1024];
- DWORD buflen = 1024;
- addr.sin_addr = *(struct in_addr *)he->h_addr_list[i++];
- if (NO_ERROR == WSAAddressToStringA((LPSOCKADDR)&addr, sizeof(addr), NULL, buf, &buflen))
- printf("\tIPv4 Address #%d: %s\n", i, buf);
- else
- printf("\tIPv4 Address #%d: Can't convert: %lu\n", i, GetLastError());
- }
- }
- else if (he->h_addrtype == AF_INET6)
- {
- struct sockaddr_in6 addr;
- memset(&addr, 0, sizeof(addr));
- addr.sin6_family = AF_INET6;
- addr.sin6_port = 0;
- i = 0;
- while (he->h_addr_list[i] != 0)
- {
- char buf[1024];
- DWORD buflen = 1024;
- addr.sin6_addr = *(struct in6_addr *)he->h_addr_list[i++];
- if (NO_ERROR == WSAAddressToStringA((LPSOCKADDR)&addr, sizeof(addr), NULL, buf, &buflen))
- printf("\tIPv6 Address #%d: %s\n", i, buf);
- else
- printf("\tIPv6 Address #%d: Can't convert: %lu\n", i, GetLastError());
- }
- }
-}
-
-
-int
-main(int argc, char **argv)
-{
- int ret;
- int r = 1;
- WSADATA wsd;
- GUID prov;
- GUID sc;
- wchar_t *cmdl;
- int wargc;
- wchar_t **wargv;
-
- if (WSAStartup(MAKEWORD(2, 2), &wsd) != 0)
- {
- fprintf(stderr, "WSAStartup() failed: %lu\n", GetLastError());
- return 5;
- }
-
- cmdl = GetCommandLineW();
- if (cmdl == NULL)
- {
- WSACleanup();
- return 2;
- }
- wargv = CommandLineToArgvW(cmdl, &wargc);
- if (wargv == NULL)
- {
- WSACleanup();
- return 3;
- }
- r = 4;
-
- if (wargc == 5)
- {
- if (wcscmp(wargv[1], L"A") == 0)
- sc = SVCID_DNS_TYPE_A;
- else if (wcscmp(wargv[1], L"AAAA") == 0)
- sc = SVCID_DNS_TYPE_AAAA;
- else if (wcscmp(wargv[1], L"name") == 0)
- sc = SVCID_HOSTNAME;
- else if (wcscmp(wargv[1], L"addr") == 0)
- sc = SVCID_INET_HOSTADDRBYNAME;
- else
- wargc -= 1;
- if (wcscmp(wargv[4], L"mswdns") == 0)
- prov = W32_DNS;
- else if (wcscmp(wargv[4], L"gnunetdns") == 0)
- prov = GNUNET_NAMESPACE_PROVIDER_DNS;
- else
- wargc -= 1;
- }
- else if (wargc == 3)
- {
- }
- else
- {
- fprintf(stderr, "Usage: %S <record type> <service name> <NSP library path> <NSP id>\n"
- "record type - one of the following: A | AAAA | name | addr\n"
- "service name - a string to resolve; \" \" (a space) means 'blank'\n"
- "NSP library path - path to libw32nsp\n"
- "NSP id - one of the following: mswdns | gnunetdns\n",
- wargv[0]);
- }
-
- if (wargc == 5)
- {
- HMODULE nsp;
-
- nsp = LoadLibraryW(wargv[3]);
- if (nsp == NULL)
- {
- fprintf(stderr, "Failed to load library `%S'\n", wargv[3]);
- }
- else
- {
- LPNSPSTARTUP startup = (LPNSPSTARTUP)GetProcAddress(nsp, "NSPStartup");
- if (startup == NULL)
- startup = (LPNSPSTARTUP)GetProcAddress(nsp, "NSPStartup@8");
- if (startup != NULL)
- {
- NSP_ROUTINE api;
- api.cbSize = sizeof(api);
- ret = startup(&prov, &api);
- if (NO_ERROR != ret)
- fprintf(stderr, "startup failed: %lu\n", GetLastError());
- else
- {
- HANDLE lookup;
- WSAQUERYSETW search;
- char buf[4096];
- WSAQUERYSETW *result = (WSAQUERYSETW *)buf;
- DWORD resultsize;
- DWORD err;
- memset(&search, 0, sizeof(search));
- search.dwSize = sizeof(search);
- search.lpszServiceInstanceName = (wcscmp(wargv[2], L" ") == 0) ? NULL : wargv[2];
- search.lpServiceClassId = &sc;
- search.lpNSProviderId = &prov;
- search.dwNameSpace = NS_ALL;
- ret = api.NSPLookupServiceBegin(&prov, &search, NULL, LUP_RETURN_ALL, &lookup);
- if (ret != NO_ERROR)
- {
- fprintf(stderr, "lookup start failed\n");
- }
- else
- {
- resultsize = 4096;
- ret = api.NSPLookupServiceNext(lookup, LUP_RETURN_ALL, &resultsize, result);
- err = GetLastError();
- if (ret != NO_ERROR)
- {
- fprintf(stderr, "lookup next failed: %lu\n", err);
- }
- else
- {
- int i;
- printf("Got result:\n");
- printf(" lpszServiceInstanceName: %S\n", result->lpszServiceInstanceName ? result->lpszServiceInstanceName : L"NULL");
- if (result->lpServiceClassId)
- printf(" lpServiceClassId: { 0x%08lX,0x%04X,0x%04X, { 0x%02X, 0x%02X, 0x%02X, 0x%02X, 0x%02X, 0x%02X, 0x%02X, 0x%02X } }\n",
- result->lpServiceClassId->Data1, result->lpServiceClassId->Data2, result->lpServiceClassId->Data3, result->lpServiceClassId->Data4[0],
- result->lpServiceClassId->Data4[1], result->lpServiceClassId->Data4[2], result->lpServiceClassId->Data4[3], result->lpServiceClassId->Data4[4],
- result->lpServiceClassId->Data4[5], result->lpServiceClassId->Data4[6], result->lpServiceClassId->Data4[7]);
- else
- printf(" lpServiceClassId: NULL\n");
- if (result->lpVersion)
- printf(" lpVersion: 0x%08lX, %d\n", result->lpVersion->dwVersion, result->lpVersion->ecHow);
- else
- printf(" lpVersion: NULL\n");
- printf(" lpszComment: %S\n", result->lpszComment ? result->lpszComment : L"NULL");
- printf(" dwNameSpace: %lu\n", result->dwNameSpace);
- if (result->lpNSProviderId)
- printf(" lpNSProviderId: { 0x%08lX,0x%04X,0x%04X, { 0x%02X, 0x%02X, 0x%02X, 0x%02X, 0x%02X, 0x%02X, 0x%02X, 0x%02X } }\n",
- result->lpNSProviderId->Data1, result->lpNSProviderId->Data2, result->lpNSProviderId->Data3, result->lpNSProviderId->Data4[0],
- result->lpNSProviderId->Data4[1], result->lpNSProviderId->Data4[2], result->lpNSProviderId->Data4[3], result->lpNSProviderId->Data4[4],
- result->lpNSProviderId->Data4[5], result->lpNSProviderId->Data4[6], result->lpNSProviderId->Data4[7]);
- else
- printf(" lpNSProviderId: NULL\n");
- printf(" lpszContext: %S\n", result->lpszContext ? result->lpszContext : L"NULL");
- printf(" dwNumberOfProtocols: %lu\n", result->dwNumberOfProtocols);
- printf(" lpszQueryString: %S\n", result->lpszQueryString ? result->lpszQueryString : L"NULL");
- printf(" dwNumberOfCsAddrs: %lu\n", result->dwNumberOfCsAddrs);
- for (i = 0; i < result->dwNumberOfCsAddrs; i++)
- {
- switch (result->lpcsaBuffer[i].iSocketType)
- {
- case SOCK_STREAM:
- printf(" %d: iSocketType = SOCK_STREAM\n", i);
- break;
-
- case SOCK_DGRAM:
- printf(" %d: iSocketType = SOCK_DGRAM\n", i);
- break;
-
- default:
- printf(" %d: iSocketType = %d\n", i, result->lpcsaBuffer[i].iSocketType);
- }
- switch (result->lpcsaBuffer[i].iProtocol)
- {
- case IPPROTO_TCP:
- printf(" %d: iProtocol = IPPROTO_TCP\n", i);
- break;
-
- case IPPROTO_UDP:
- printf(" %d: iProtocol = IPPROTO_UDP\n", i);
- break;
-
- default:
- printf(" %d: iProtocol = %d\n", i, result->lpcsaBuffer[i].iProtocol);
- }
- switch (result->lpcsaBuffer[i].LocalAddr.lpSockaddr->sa_family)
- {
- case AF_INET:
- printf(" %d: loc family = AF_INET\n", i);
- break;
-
- case AF_INET6:
- printf(" %d: loc family = AF_INET6\n", i);
- break;
-
- default:
- printf(" %d: loc family = %hu\n", i, result->lpcsaBuffer[i].LocalAddr.lpSockaddr->sa_family);
- }
- switch (result->lpcsaBuffer[i].RemoteAddr.lpSockaddr->sa_family)
- {
- case AF_INET:
- printf(" %d: rem family = AF_INET\n", i);
- break;
-
- case AF_INET6:
- printf(" %d: rem family = AF_INET6\n", i);
- break;
-
- default:
- printf(" %d: rem family = %hu\n", i, result->lpcsaBuffer[i].RemoteAddr.lpSockaddr->sa_family);
- }
- char buf[1024];
- DWORD buflen = 1024;
- if (NO_ERROR == WSAAddressToStringA(result->lpcsaBuffer[i].LocalAddr.lpSockaddr, result->lpcsaBuffer[i].LocalAddr.iSockaddrLength, NULL, buf, &buflen))
- printf("\tLocal Address #%d: %s\n", i, buf);
- else
- printf("\tLocal Address #%d: Can't convert: %lu\n", i, GetLastError());
- buflen = 1024;
- if (NO_ERROR == WSAAddressToStringA(result->lpcsaBuffer[i].RemoteAddr.lpSockaddr, result->lpcsaBuffer[i].RemoteAddr.iSockaddrLength, NULL, buf, &buflen))
- printf("\tRemote Address #%d: %s\n", i, buf);
- else
- printf("\tRemote Address #%d: Can't convert: %lu\n", i, GetLastError());
- }
- printf(" dwOutputFlags: 0x%08lX\n", result->dwOutputFlags);
- printf(" lpBlob: 0x%p\n", result->lpBlob);
- if (result->lpBlob)
- {
- struct hostent *he = malloc(result->lpBlob->cbSize);
- if (he != NULL)
- {
- GNUNET_memcpy(he, result->lpBlob->pBlobData, result->lpBlob->cbSize);
- UnpackHostEnt(he);
- print_hostent(he);
- free(he);
- }
- }
- }
- ret = api.NSPLookupServiceEnd(lookup);
- if (ret != NO_ERROR)
- printf("NSPLookupServiceEnd() failed: %lu\n", GetLastError());
- }
- api.NSPCleanup(&prov);
- }
- }
- FreeLibrary(nsp);
- }
- }
- else if (wargc == 3)
- {
- int s;
- ADDRINFOW hints;
- ADDRINFOW *result;
- ADDRINFOW *pos;
-
- memset(&hints, 0, sizeof(struct addrinfo));
- hints.ai_family = AF_UNSPEC;
- hints.ai_socktype = SOCK_STREAM;
-
- if (0 != (s = GetAddrInfoW(wargv[2], NULL, &hints, &result)))
- {
- fprintf(stderr, "Cound not resolve `%S' using GetAddrInfoW: %lu\n",
- wargv[2], GetLastError());
- }
- else
- {
- for (pos = result; pos != NULL; pos = pos->ai_next)
- {
- wchar_t tmpbuf[1024];
- DWORD buflen = 1024;
- if (0 == WSAAddressToStringW(pos->ai_addr, pos->ai_addrlen, NULL, tmpbuf, &buflen))
- fprintf(stderr, "Result:\n"
- " flags: 0x%X\n"
- " family: 0x%X\n"
- " socktype: 0x%X\n"
- " protocol: 0x%X\n"
- " addrlen: %u\n"
- " addr: %S\n"
- " canonname: %S\n",
- pos->ai_flags,
- pos->ai_family,
- pos->ai_socktype,
- pos->ai_protocol,
- pos->ai_addrlen,
- tmpbuf,
- pos->ai_canonname);
- else
- fprintf(stderr, "Result:\n"
- " flags: 0x%X\n"
- " family: 0x%X\n"
- " socktype: 0x%X\n"
- " protocol: 0x%X\n"
- " addrlen: %u\n"
- " addr: %S\n"
- " canonname: %S\n",
- pos->ai_flags,
- pos->ai_family,
- pos->ai_socktype,
- pos->ai_protocol,
- pos->ai_addrlen,
- L"<can't stringify>",
- pos->ai_canonname);
- }
- if (NULL != result)
- FreeAddrInfoW(result);
- }
- }
- WSACleanup();
- return r;
-}
diff --git a/src/gns/w32nsp-uninstall.c b/src/gns/w32nsp-uninstall.c
deleted file mode 100644
index f5031f341..000000000
--- a/src/gns/w32nsp-uninstall.c
+++ /dev/null
@@ -1,31 +0,0 @@
-#include <ws2spi.h>
-#include <windows.h>
-#include <nspapi.h>
-#include <initguid.h>
-#include "gnunet_w32nsp_lib.h"
-#include <stdio.h>
-
-int
-main(int argc, char **argv)
-{
- int ret;
- GUID id = GNUNET_NAMESPACE_PROVIDER_DNS;
- WSADATA wsd;
-
- if (WSAStartup(MAKEWORD(2, 2), &wsd) != 0)
- {
- fprintf(stderr, "WSAStartup () failed: %lu\n", GetLastError());
- return 5;
- }
-
- ret = WSCUnInstallNameSpace(&id);
- if (ret == NO_ERROR)
- {
- fprintf(stderr, "Uninstalled GNUnet DNS provider\n");
- WSACleanup();
- return 0;
- }
- fprintf(stderr, "WSCUnInstallNameSpace () failed: %lu\n", GetLastError());
- WSACleanup();
- return 1;
-} \ No newline at end of file
diff --git a/src/gns/w32nsp.c b/src/gns/w32nsp.c
deleted file mode 100644
index 3de4452f0..000000000
--- a/src/gns/w32nsp.c
+++ /dev/null
@@ -1,711 +0,0 @@
-/*
- This file is part of GNUnet.
- Copyright (C) 2012 GNUnet e.V.
-
- GNUnet is free software: you can redistribute it and/or modify it
- under the terms of the GNU Affero General Public License as published
- by the Free Software Foundation, either version 3 of the License,
- or (at your option) any later version.
-
- GNUnet is distributed in the hope that it will be useful, but
- WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- Affero General Public License for more details.
-
- You should have received a copy of the GNU Affero General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>.
-
- SPDX-License-Identifier: AGPL3.0-or-later
- */
-/**
- * @file gns/w32nsp.c
- * @brief W32 integration for GNS
- * @author LRN
- */
-/* This code is partially based upon samples from the book
- * "Network Programming For Microsoft Windows, 2Nd Edition".
- */
-
-#define VERBOSE 0
-#if !VERBOSE
-# define DEBUGLOG(s, ...)
-#endif
-#if VERBOSE
-# define __printf__ printf
-# define DEBUGLOG(s, ...) printf(s, ## __VA_ARGS__)
-#endif
-
-#include <stdint.h>
-#include <ws2tcpip.h>
-#include <ws2spi.h>
-#include <windows.h>
-#include <nspapi.h>
-
-#define WINDOWS 1
-#define MINGW 1
-#ifndef __BYTE_ORDER
-#ifdef _BYTE_ORDER
-#define __BYTE_ORDER _BYTE_ORDER
-#else
-#ifdef BYTE_ORDER
-#define __BYTE_ORDER BYTE_ORDER
-#endif
-#endif
-#endif
-#ifndef __BIG_ENDIAN
-#ifdef _BIG_ENDIAN
-#define __BIG_ENDIAN _BIG_ENDIAN
-#else
-#ifdef BIG_ENDIAN
-#define __BIG_ENDIAN BIG_ENDIAN
-#endif
-#endif
-#endif
-#ifndef __LITTLE_ENDIAN
-#ifdef _LITTLE_ENDIAN
-#define __LITTLE_ENDIAN _LITTLE_ENDIAN
-#else
-#ifdef LITTLE_ENDIAN
-#define __LITTLE_ENDIAN LITTLE_ENDIAN
-#endif
-#endif
-#endif
-#include "w32resolver.h"
-#include <initguid.h>
-#include "gnunet_w32nsp_lib.h"
-#undef INITGUID
-
-#define NSPAPI_VERSION_MAJOR 4
-#define NSPAPI_VERSION_MINOR 4
-
-static CRITICAL_SECTION records_cs;
-
-struct record {
- _win_socket s;
- DWORD flags;
- uint8_t state;
- char *buf;
- wchar_t *name;
-};
-
-static struct record *records = NULL;
-static size_t records_len = 0;
-static size_t records_size = 0;
-
-static int
-resize_records()
-{
- size_t new_size = records_len > 0 ? records_len * 2 : 5;
- struct record *new_records = malloc(new_size * sizeof(struct record));
-
- if (new_records == NULL)
- {
- SetLastError(WSA_NOT_ENOUGH_MEMORY);
- return 0;
- }
- GNUNET_memcpy(new_records, records, records_len * sizeof(struct record));
- memset(&new_records[records_len], 0, sizeof(struct record) * (new_size - records_len));
- records_size = new_size;
- free(records);
- records = new_records;
- return 1;
-}
-
-static int
-add_record(_win_socket s, const wchar_t *name, DWORD flags)
-{
- int res = 1;
- int i;
- int empty = -1;
-
- //EnterCriticalSection (&records_cs);
- for (i = 0; i < records_len; i++)
- if (records[i].state == 0)
- break;
- empty = i;
- if (i == records_len)
- {
- res = resize_records();
- if (res)
- empty = records_len++;
- }
- if (res)
- {
- struct record r;
- r.s = s;
- r.flags = flags;
- r.name = (wchar_t *)name;
- r.state = 1;
- r.buf = NULL;
- if (name)
- r.name = wcsdup(name);
- records[empty] = r;
- }
- //LeaveCriticalSection (&records_cs);
- return res;
-}
-
-/* These are not defined by mingw.org headers at the moment*/
-typedef INT (WSPAPI *LPNSPIOCTL)(HANDLE, DWORD, LPVOID, DWORD, LPVOID, DWORD, LPDWORD, LPWSACOMPLETION, LPWSATHREADID);
-typedef struct _NSP_ROUTINE_XP {
- DWORD cbSize;
- DWORD dwMajorVersion;
- DWORD dwMinorVersion;
- LPNSPCLEANUP NSPCleanup;
- LPNSPLOOKUPSERVICEBEGIN NSPLookupServiceBegin;
- LPNSPLOOKUPSERVICENEXT NSPLookupServiceNext;
- LPNSPLOOKUPSERVICEEND NSPLookupServiceEnd;
- LPNSPSETSERVICE NSPSetService;
- LPNSPINSTALLSERVICECLASS NSPInstallServiceClass;
- LPNSPREMOVESERVICECLASS NSPRemoveServiceClass;
- LPNSPGETSERVICECLASSINFO NSPGetServiceClassInfo;
- LPNSPIOCTL NSPIoctl;
-} NSP_ROUTINE_XP;
-
-static _win_socket
-connect_to_dns_resolver()
-{
- struct sockaddr_in addr;
- _win_socket r;
- int ret;
-
- r = _win_socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
- if (INVALID_SOCKET == r)
- {
- SetLastError(16004);
- return r;
- }
-
- addr.sin_family = AF_INET;
- addr.sin_port = htons(5353); /* TCP 5353 is not registered; UDP 5353 is */
- addr.sin_addr.s_addr = inet_addr("127.0.0.1");
-
- ret = _win_connect(r, (struct sockaddr *)&addr, sizeof(addr));
- if (SOCKET_ERROR == ret)
- {
- DWORD err = GetLastError();
- closesocket(r);
- SetLastError(err);
- SetLastError(16005);
- r = INVALID_SOCKET;
- }
- return r;
-}
-
-static int
-send_name_to_ip_request(LPWSAQUERYSETW lpqsRestrictions,
- LPWSASERVICECLASSINFOW lpServiceClassInfo, DWORD dwControlFlags,
- _win_socket *resolver)
-{
- struct GNUNET_W32RESOLVER_GetMessage *msg;
- int af4 = 0;
- int af6 = 0;
- char *buf;
- int ret = 1;
- int i;
- size_t size = sizeof(struct GNUNET_W32RESOLVER_GetMessage);
- size_t namelen = 0;
-
- if (lpqsRestrictions->lpszServiceInstanceName)
- namelen = sizeof(wchar_t) * (wcslen(lpqsRestrictions->lpszServiceInstanceName) + 1);
- size += namelen;
- buf = malloc(size);
- msg = (struct GNUNET_W32RESOLVER_GetMessage *)buf;
- msg->header.size = htons(size);
- msg->header.type = htons(GNUNET_MESSAGE_TYPE_W32RESOLVER_REQUEST);
- if (lpqsRestrictions->dwNumberOfProtocols > 0)
- {
- int i;
- for (i = 0; i < lpqsRestrictions->dwNumberOfProtocols; i++)
- {
- if (lpqsRestrictions->lpafpProtocols[0].iAddressFamily == AF_INET)
- af4 = 1;
- if (lpqsRestrictions->lpafpProtocols[0].iAddressFamily == AF_INET6)
- af6 = 1;
- }
- }
- if (af4 && !af6)
- msg->af = htonl(AF_INET);
- else if (af6 && !af4)
- msg->af = htonl(AF_INET6);
- else
- msg->af = htonl(AF_UNSPEC);
- if (lpqsRestrictions->lpszServiceInstanceName)
- GNUNET_memcpy(&msg[1], lpqsRestrictions->lpszServiceInstanceName, namelen);
- msg->sc_data1 = htonl(lpqsRestrictions->lpServiceClassId->Data1);
- msg->sc_data2 = htons(lpqsRestrictions->lpServiceClassId->Data2);
- msg->sc_data3 = htons(lpqsRestrictions->lpServiceClassId->Data3);
- for (i = 0; i < 8; i++)
- msg->sc_data4[i] = lpqsRestrictions->lpServiceClassId->Data4[i];
- *resolver = connect_to_dns_resolver();
- if (*resolver != INVALID_SOCKET)
- {
- if (size != send(*resolver, buf, size, 0))
- {
-#if VERBOSE
- DWORD err = GetLastError();
-#endif
- closesocket(*resolver);
- *resolver = INVALID_SOCKET;
- DEBUGLOG("GNUNET_W32NSP_LookupServiceBegin: failed to send request: %lu\n", err);
- SetLastError(WSATRY_AGAIN);
- ret = 0;
- }
- }
- else
- ret = 0;
- free(buf);
- return ret;
-}
-
-static int WSPAPI
-NSPCleanup(LPGUID lpProviderId)
-{
- DEBUGLOG("NSPCleanup\n");
- if (IsEqualGUID(lpProviderId, &GNUNET_NAMESPACE_PROVIDER_DNS))
- {
- return NO_ERROR;
- }
- SetLastError(WSAEINVALIDPROVIDER);
- return SOCKET_ERROR;
-}
-
-BOOL WINAPI
-DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
-{
- switch (fdwReason)
- {
- case DLL_PROCESS_ATTACH:
- if (!InitializeCriticalSectionAndSpinCount(&records_cs, 0x00000400))
- {
- return FALSE;
- }
- break;
-
- case DLL_THREAD_ATTACH:
- break;
-
- case DLL_THREAD_DETACH:
- break;
-
- case DLL_PROCESS_DETACH:
- DeleteCriticalSection(&records_cs);
- break;
- }
- return TRUE;
-}
-
-
-
-
-static int WSPAPI
-GNUNET_W32NSP_LookupServiceBegin(LPGUID lpProviderId, LPWSAQUERYSETW lpqsRestrictions,
- LPWSASERVICECLASSINFOW lpServiceClassInfo, DWORD dwControlFlags,
- LPHANDLE lphLookup)
-{
- DEBUGLOG("GNUNET_W32NSP_LookupServiceBegin\n");
- if (IsEqualGUID(lpProviderId, &GNUNET_NAMESPACE_PROVIDER_DNS))
- {
- SOCKET s;
- if (lpqsRestrictions->dwNameSpace != NS_DNS && lpqsRestrictions->dwNameSpace != NS_ALL)
- {
- DEBUGLOG("GNUNET_W32NSP_LookupServiceBegin: wrong namespace\n");
- SetLastError(WSAEINVAL);
- return SOCKET_ERROR;
- }
- if (lpqsRestrictions->lpszServiceInstanceName != NULL)
- {
- wchar_t *s = lpqsRestrictions->lpszServiceInstanceName;
- size_t len = wcslen(s);
- if (len >= 5 && wcscmp(&s[len - 5], L".zkey") == 0)
- {
- }
- else if (len >= 4 && wcscmp(&s[len - 4], L".gnu") == 0)
- {
- }
- else
- {
- DEBUGLOG("GNUNET_W32NSP_LookupServiceBegin: unsupported TLD\n");
- SetLastError(WSAEINVAL);
- return SOCKET_ERROR;
- }
- }
-
- if (send_name_to_ip_request(lpqsRestrictions,
- lpServiceClassInfo, dwControlFlags, &s))
- {
- if (!(add_record(s, lpqsRestrictions->lpszServiceInstanceName, dwControlFlags)))
- {
- DWORD err = GetLastError();
- DEBUGLOG("GNUNET_W32NSP_LookupServiceBegin: failed to add a record\n");
- closesocket(s);
- SetLastError(err);
- return SOCKET_ERROR;
- }
- *lphLookup = (HANDLE)s;
- DEBUGLOG("GNUNET_W32NSP_LookupServiceBegin: OK (%lu)\n", GetLastError());
- return NO_ERROR;
- }
- return SOCKET_ERROR;
- }
- DEBUGLOG("GNUNET_W32NSP_LookupServiceBegin: wrong provider\n");
- SetLastError(WSAEINVALIDPROVIDER);
- return SOCKET_ERROR;
-}
-
-#define UnmarshallPtr(ptr, ptrtype, base) \
- if (ptr) \
- ptr = (ptrtype *) (base + (uintptr_t)ptr)
-
-static void
-UnmarshallWSAQUERYSETW(LPWSAQUERYSETW req)
-{
- int i;
- char *base = (char *)req;
-
- UnmarshallPtr(req->lpszServiceInstanceName, wchar_t, base);
- UnmarshallPtr(req->lpServiceClassId, GUID, base);
- UnmarshallPtr(req->lpVersion, WSAVERSION, base);
- UnmarshallPtr(req->lpszComment, wchar_t, base);
- UnmarshallPtr(req->lpNSProviderId, GUID, base);
- UnmarshallPtr(req->lpszContext, wchar_t, base);
- UnmarshallPtr(req->lpafpProtocols, AFPROTOCOLS, base);
- UnmarshallPtr(req->lpszQueryString, wchar_t, base);
- UnmarshallPtr(req->lpcsaBuffer, CSADDR_INFO, base);
- for (i = 0; i < req->dwNumberOfCsAddrs; i++)
- {
- UnmarshallPtr(req->lpcsaBuffer[i].LocalAddr.lpSockaddr, SOCKADDR, base);
- UnmarshallPtr(req->lpcsaBuffer[i].RemoteAddr.lpSockaddr, SOCKADDR, base);
- }
- UnmarshallPtr(req->lpBlob, BLOB, base);
- if (req->lpBlob)
- UnmarshallPtr(req->lpBlob->pBlobData, BYTE, base);
-}
-
-static int WSAAPI
-GNUNET_W32NSP_LookupServiceNext(HANDLE hLookup, DWORD dwControlFlags,
- LPDWORD lpdwBufferLength, LPWSAQUERYSETW lpqsResults)
-{
- /*DWORD effective_flags;*/
- int i;
- struct GNUNET_MessageHeader header = { 0, 0 };
- int rec = -1;
- int rc;
- int to_receive;
- int t;
- char *buf;
-
- DEBUGLOG("GNUNET_W32NSP_LookupServiceNext\n");
- //EnterCriticalSection (&records_cs);
- for (i = 0; i < records_len; i++)
- {
- if (records[i].s == (_win_socket)hLookup)
- {
- rec = i;
- break;
- }
- }
- if (rec == -1)
- {
- DEBUGLOG("GNUNET_W32NSP_LookupServiceNext: invalid handle\n");
- SetLastError(WSA_INVALID_HANDLE);
- //LeaveCriticalSection (&records_cs);
- return SOCKET_ERROR;
- }
- if (records[rec].state & 4)
- {
- DEBUGLOG("GNUNET_W32NSP_LookupServiceNext: session is closed\n");
- SetLastError(WSA_E_NO_MORE);
- //LeaveCriticalSection (&records_cs);
- return SOCKET_ERROR;
- }
- /*effective_flags = dwControlFlags & records[rec].flags;*/
- if (records[rec].buf)
- {
- DEBUGLOG("GNUNET_W32NSP_LookupServiceNext: checking buffer\n");
- header = *((struct GNUNET_MessageHeader *)records[rec].buf);
- if (*lpdwBufferLength < header.size - sizeof(struct GNUNET_W32RESOLVER_GetMessage))
- {
- DEBUGLOG("GNUNET_W32NSP_LookupServiceNext: client buffer is too small\n");
- SetLastError(WSAEFAULT);
- //LeaveCriticalSection (&records_cs);
- return SOCKET_ERROR;
- }
- GNUNET_memcpy(lpqsResults, &((struct GNUNET_W32RESOLVER_GetMessage *)records[rec].buf)[1], header.size - sizeof(struct GNUNET_W32RESOLVER_GetMessage));
- free(records[rec].buf);
- records[rec].buf = NULL;
- //LeaveCriticalSection (&records_cs);
- UnmarshallWSAQUERYSETW((LPWSAQUERYSETW)lpqsResults);
- DEBUGLOG("GNUNET_W32NSP_LookupServiceNext: OK (from buffer)\n");
- return NO_ERROR;
- }
- records[rec].state |= 8;
- //LeaveCriticalSection (&records_cs);
- to_receive = sizeof(header);
- rc = 0;
-#if VERBOSE
- {
- unsigned long have;
- int ior = ioctlsocket((_win_socket)hLookup, FIONREAD, &have);
- DEBUGLOG("GNUNET_W32NSP_LookupServiceNext: reading %d bytes as a header from %p, %lu bytes available\n", to_receive, hLookup, have);
- }
-#endif
- while (to_receive > 0)
- {
- t = recv((_win_socket)hLookup, &((char *)&header)[rc], to_receive, 0);
- if (t > 0)
- {
- rc += t;
- to_receive -= t;
- }
- else
- break;
- }
-#if VERBOSE
- {
- unsigned long have;
- int ior = ioctlsocket((_win_socket)hLookup, FIONREAD, &have);
- DEBUGLOG("GNUNET_W32NSP_LookupServiceNext: read %d bytes as a header from %p, %lu bytes available\n", rc, hLookup, have);
- }
-#endif
- //EnterCriticalSection (&records_cs);
- records[rec].state &= ~8;
- if (rc != sizeof(header))
- {
- if (records[rec].state & 2)
- {
- DEBUGLOG("GNUNET_W32NSP_LookupServiceNext: call cancelled\n");
- SetLastError(WSA_E_CANCELLED);
- }
- else
- {
- DEBUGLOG("GNUNET_W32NSP_LookupServiceNext: failed to receive enough data for a header (rc %d != %u, state is 0x%0X)\n", rc, sizeof(header), records[rec].state);
- SetLastError(WSA_E_NO_MORE);
- }
- records[rec].state |= 4;
- //LeaveCriticalSection (&records_cs);
- return SOCKET_ERROR;
- }
- records[rec].state &= ~8;
- header.type = ntohs(header.type);
- header.size = ntohs(header.size);
- DEBUGLOG("GNUNET_W32NSP_LookupServiceNext: header type %d, header size %u\n", header.type, header.size);
- if (header.type != GNUNET_MESSAGE_TYPE_W32RESOLVER_RESPONSE ||
- (header.type == GNUNET_MESSAGE_TYPE_W32RESOLVER_RESPONSE &&
- header.size == sizeof(header)))
- {
- records[rec].state |= 4;
- if (header.type != GNUNET_MESSAGE_TYPE_W32RESOLVER_RESPONSE)
- DEBUGLOG("GNUNET_W32NSP_LookupServiceNext: header type is wrong\n");
- else
- DEBUGLOG("GNUNET_W32NSP_LookupServiceNext: empty header - no data\n");
- //LeaveCriticalSection (&records_cs);
- SetLastError(WSA_E_NO_MORE);
- return SOCKET_ERROR;
- }
- buf = malloc(header.size);
- if (buf == NULL)
- {
- records[rec].state |= 4;
- DEBUGLOG("GNUNET_W32NSP_LookupServiceNext: malloc() failed\n");
- //LeaveCriticalSection (&records_cs);
- SetLastError(WSA_E_NO_MORE);
- return SOCKET_ERROR;
- }
- records[rec].state |= 8;
- //LeaveCriticalSection (&records_cs);
- GNUNET_memcpy(buf, &header, sizeof(header));
- to_receive = header.size - sizeof(header);
- rc = 0;
-#if VERBOSE
- {
- unsigned long have;
- int ior = ioctlsocket((_win_socket)hLookup, FIONREAD, &have);
- DEBUGLOG("GNUNET_W32NSP_LookupServiceNext: reading %d bytes as a body from %p, %lu bytes available\n", to_receive, hLookup, have);
- }
-#endif
- while (to_receive > 0)
- {
- DEBUGLOG("GNUNET_W32NSP_LookupServiceNext: recv (%d)\n", to_receive);
- t = recv((_win_socket)hLookup, &((char *)&((struct GNUNET_MessageHeader *)buf)[1])[rc], to_receive, 0);
- DEBUGLOG("GNUNET_W32NSP_LookupServiceNext: recv returned %d\n", t);
- if (t > 0)
- {
- rc += t;
- to_receive -= t;
- }
- else
- break;
- }
-#if VERBOSE
- {
- unsigned long have;
- int ior = ioctlsocket((_win_socket)hLookup, FIONREAD, &have);
- DEBUGLOG("GNUNET_W32NSP_LookupServiceNext: read %d bytes as a body from %p, %lu bytes available\n", rc, hLookup, have);
- }
-#endif
- //EnterCriticalSection (&records_cs);
- records[rec].state &= ~8;
- if (rc != header.size - sizeof(header))
- {
- free(buf);
- if (records[rec].state & 2)
- {
- DEBUGLOG("GNUNET_W32NSP_LookupServiceNext: call cancelled\n");
- SetLastError(WSA_E_CANCELLED);
- }
- else
- {
- DEBUGLOG("GNUNET_W32NSP_LookupServiceNext: failed to receive enough data for the rest (rc %d != %d, state is 0x%0X)\n", rc, header.size - sizeof(header), records[rec].state);
- SetLastError(WSA_E_NO_MORE);
- }
- records[rec].state |= 4;
- //LeaveCriticalSection (&records_cs);
- return SOCKET_ERROR;
- }
- if (*lpdwBufferLength < header.size - sizeof(struct GNUNET_W32RESOLVER_GetMessage))
- {
- DEBUGLOG("GNUNET_W32NSP_LookupServiceNext: client buffer is too small\n");
- SetLastError(WSAEFAULT);
- records[rec].buf = buf;
- //LeaveCriticalSection (&records_cs);
- return SOCKET_ERROR;
- }
- //LeaveCriticalSection (&records_cs);
- DEBUGLOG("GNUNET_W32NSP_LookupServiceNext: writing %d bytes into result buffer\n", header.size - sizeof(struct GNUNET_W32RESOLVER_GetMessage));
- GNUNET_memcpy(lpqsResults, &((struct GNUNET_W32RESOLVER_GetMessage *)buf)[1], header.size - sizeof(struct GNUNET_W32RESOLVER_GetMessage));
- free(buf);
- DEBUGLOG("GNUNET_W32NSP_LookupServiceNext: OK\n");
- UnmarshallWSAQUERYSETW((LPWSAQUERYSETW)lpqsResults);
- DEBUGLOG("GNUNET_W32NSP_LookupServiceNext: returning (%lu)\n", GetLastError());
- return NO_ERROR;
-}
-
-static int WSPAPI
-GNUNET_W32NSP_LookupServiceEnd(HANDLE hLookup)
-{
- int i;
- int rec = -1;
-
- DEBUGLOG("GNUNET_W32NSP_LookupServiceEnd\n");
- //EnterCriticalSection (&records_cs);
- for (i = 0; i < records_len; i++)
- {
- if (records[i].s == (_win_socket)hLookup)
- {
- rec = i;
- break;
- }
- }
- if (rec == -1)
- {
- SetLastError(WSA_INVALID_HANDLE);
- //LeaveCriticalSection (&records_cs);
- DEBUGLOG("GNUNET_W32NSP_LookupServiceEnd: invalid handle\n");
- return SOCKET_ERROR;
- }
- records[rec].state |= 2;
- closesocket(records[rec].s);
- while (records[rec].state & 8)
- {
- //LeaveCriticalSection (&records_cs);
- Sleep(10);
- //EnterCriticalSection (&records_cs);
- }
- if (records[rec].buf)
- free(records[rec].buf);
- records[rec].buf = NULL;
- records[rec].state = 0;
- if (records[rec].name)
- free(records[rec].name);
- //LeaveCriticalSection (&records_cs);
- DEBUGLOG("GNUNET_W32NSP_LookupServiceEnd: OK\n");
- return NO_ERROR;
-}
-
-static int WSAAPI
-GNUNET_W32NSP_SetService(LPGUID lpProviderId,
- LPWSASERVICECLASSINFOW lpServiceClassInfo, LPWSAQUERYSETW lpqsRegInfo,
- WSAESETSERVICEOP essOperation, DWORD dwControlFlags)
-{
- DEBUGLOG("GNUNET_W32NSP_SetService\n");
- SetLastError(WSAEOPNOTSUPP);
- return SOCKET_ERROR;
-}
-
-static int WSAAPI
-GNUNET_W32NSP_InstallServiceClass(LPGUID lpProviderId,
- LPWSASERVICECLASSINFOW lpServiceClassInfo)
-{
- DEBUGLOG("GNUNET_W32NSP_InstallServiceClass\n");
- SetLastError(WSAEOPNOTSUPP);
- return SOCKET_ERROR;
-}
-
-
-static int WSAAPI
-GNUNET_W32NSP_RemoveServiceClass(LPGUID lpProviderId, LPGUID lpServiceClassId)
-{
- DEBUGLOG("GNUNET_W32NSP_RemoveServiceClass\n");
- SetLastError(WSAEOPNOTSUPP);
- return SOCKET_ERROR;
-}
-
-static int WSAAPI
-GNUNET_W32NSP_GetServiceClassInfo(LPGUID lpProviderId, LPDWORD lpdwBufSize,
- LPWSASERVICECLASSINFOW lpServiceClassInfo)
-{
- DEBUGLOG("GNUNET_W32NSP_GetServiceClassInfo\n");
- SetLastError(WSAEOPNOTSUPP);
- return SOCKET_ERROR;
-}
-
-static int WSAAPI
-GNUNET_W32NSP_Ioctl(HANDLE hLookup, DWORD dwControlCode, LPVOID lpvInBuffer,
- DWORD cbInBuffer, LPVOID lpvOutBuffer, DWORD cbOutBuffer,
- LPDWORD lpcbBytesReturned, LPWSACOMPLETION lpCompletion,
- LPWSATHREADID lpThreadId)
-{
- DEBUGLOG("GNUNET_W32NSP_Ioctl\n");
- SetLastError(WSAEOPNOTSUPP);
- return SOCKET_ERROR;
-}
-
-/**
- * This function is called by Winsock to hook up our provider.
- * It is the only function that [should be/is] exported by the
- * provider. All other routines are passed as pointers in lpnspRoutines.
- */
-int WSAAPI
-GNUNET_W32NSP_NSPStartup(LPGUID lpProviderId, LPNSP_ROUTINE lpnspRoutines)
-{
- if (IsEqualGUID(lpProviderId, &GNUNET_NAMESPACE_PROVIDER_DNS))
- {
- if (!connect_to_dns_resolver())
- {
- return SOCKET_ERROR;
- }
- /* This assumes that NSP_ROUTINE struct doesn't have a NSPIoctl member.
- * If it does, you need to use FIELD_OFFSET() macro to get offset of NSPIoctl
- * and use that offset as cbSize.
- */
- lpnspRoutines->cbSize = sizeof(NSP_ROUTINE);
-
- lpnspRoutines->dwMajorVersion = NSPAPI_VERSION_MAJOR;
- lpnspRoutines->dwMinorVersion = NSPAPI_VERSION_MINOR;
- lpnspRoutines->NSPCleanup = NSPCleanup;
- lpnspRoutines->NSPLookupServiceBegin = GNUNET_W32NSP_LookupServiceBegin;
- lpnspRoutines->NSPLookupServiceNext = GNUNET_W32NSP_LookupServiceNext;
- lpnspRoutines->NSPLookupServiceEnd = GNUNET_W32NSP_LookupServiceEnd;
- lpnspRoutines->NSPSetService = GNUNET_W32NSP_SetService;
- lpnspRoutines->NSPInstallServiceClass = GNUNET_W32NSP_InstallServiceClass;
- lpnspRoutines->NSPRemoveServiceClass = GNUNET_W32NSP_RemoveServiceClass;
- lpnspRoutines->NSPGetServiceClassInfo = GNUNET_W32NSP_GetServiceClassInfo;
- /*((NSP_ROUTINE_XP *) lpnspRoutines)->NSPIoctl = GNUNET_W32NSP_Ioctl;*/
- lpnspRoutines->NSPIoctl = GNUNET_W32NSP_Ioctl;
- return NO_ERROR;
- }
- SetLastError(WSAEINVALIDPROVIDER);
- return SOCKET_ERROR;
-}
-
diff --git a/src/gns/w32nsp.def b/src/gns/w32nsp.def
deleted file mode 100644
index 6bd28b283..000000000
--- a/src/gns/w32nsp.def
+++ /dev/null
@@ -1,2 +0,0 @@
-EXPORTS
-NSPStartup=GNUNET_W32NSP_NSPStartup
diff --git a/src/gnsrecord/Makefile.am b/src/gnsrecord/Makefile.am
index f840a31a4..81bee5a6b 100644
--- a/src/gnsrecord/Makefile.am
+++ b/src/gnsrecord/Makefile.am
@@ -7,10 +7,6 @@ pkgcfgdir= $(pkgdatadir)/config.d/
libexecdir= $(pkglibdir)/libexec/
-if MINGW
- WINFLAGS = -Wl,--no-undefined -Wl,--export-all-symbols
-endif
-
if USE_COVERAGE
AM_CFLAGS = --coverage -O0
XLIBS = -lgcov
diff --git a/src/hello/Makefile.am b/src/hello/Makefile.am
index 00357f9e1..7cb71cdce 100644
--- a/src/hello/Makefile.am
+++ b/src/hello/Makefile.am
@@ -1,10 +1,6 @@
# This Makefile.am is in the public domain
AM_CPPFLAGS = -I$(top_srcdir)/src/include
-if MINGW
- WINFLAGS = -Wl,--no-undefined -Wl,--export-all-symbols
-endif
-
if USE_COVERAGE
AM_CFLAGS = --coverage -O0
XLIB = -lgcov
diff --git a/src/identity/Makefile.am b/src/identity/Makefile.am
index 9c87ec2c0..39d423506 100644
--- a/src/identity/Makefile.am
+++ b/src/identity/Makefile.am
@@ -3,10 +3,6 @@ AM_CPPFLAGS = -I$(top_srcdir)/src/include
plugindir = $(libdir)/gnunet
-if MINGW
- WINFLAGS = -Wl,--no-undefined -Wl,--export-all-symbols
-endif
-
if USE_COVERAGE
AM_CFLAGS = --coverage -O0
XLIB = -lgcov
diff --git a/src/include/Makefile.am b/src/include/Makefile.am
index 775257768..d5c097341 100644
--- a/src/include/Makefile.am
+++ b/src/include/Makefile.am
@@ -3,10 +3,6 @@ SUBDIRS = .
gnunetincludedir = $(includedir)/gnunet
-if MINGW
- WINPROC = winproc.h
-endif
-
EXTRA_DIST = \
gauger.h \
block_fs.h \
@@ -15,7 +11,7 @@ EXTRA_DIST = \
if TALER_ONLY
gnunetinclude_HEADERS = \
- platform.h plibc.h $(WINPROC) gettext.h \
+ platform.h gettext.h \
gnunet_common.h \
gnunet_container_lib.h \
gnunet_crypto_lib.h \
@@ -25,7 +21,7 @@ gnunetinclude_HEADERS = \
else
gnunetinclude_HEADERS = \
- platform.h $(WINPROC) gettext.h \
+ platform.h gettext.h \
compat.h \
gnunet_applications.h \
gnunet_arm_service.h \
diff --git a/src/include/gnunet_common.h b/src/include/gnunet_common.h
index afaf3a4de..555a98eb5 100644
--- a/src/include/gnunet_common.h
+++ b/src/include/gnunet_common.h
@@ -42,9 +42,6 @@
#if HAVE_NETINET_IN_H
#include <netinet/in.h>
#endif
-#ifdef MINGW
-#include "winproc.h"
-#endif
#ifdef HAVE_STDINT_H
#include <stdint.h>
#endif
@@ -189,11 +186,7 @@ extern "C" {
/**
* gcc-ism to get gcc bitfield layout when compiling with -mms-bitfields
*/
-#if MINGW
-#define GNUNET_GCC_STRUCT_LAYOUT __attribute__ ((gcc_struct))
-#else
#define GNUNET_GCC_STRUCT_LAYOUT
-#endif
/**
* gcc-ism to force alignment; we use this to align char-arrays
@@ -216,28 +209,6 @@ extern "C" {
*/
#define GNUNET_NORETURN __attribute__ ((noreturn))
-#if MINGW
-#if __GNUC__ > 3
-/**
- * gcc 4.x-ism to pack structures even on W32 (to be used before structs);
- * Using this would cause structs to be unaligned on the stack on Sparc,
- * so we *only* use this on W32 (see #670578 from Debian); fortunately,
- * W32 doesn't run on sparc anyway.
- */
-#define GNUNET_NETWORK_STRUCT_BEGIN _Pragma("pack(push)") _Pragma ("pack(1)")
-
-/**
- * gcc 4.x-ism to pack structures even on W32 (to be used after structs)
- * Using this would cause structs to be unaligned on the stack on Sparc,
- * so we *only* use this on W32 (see #670578 from Debian); fortunately,
- * W32 doesn't run on sparc anyway.
- */
-#define GNUNET_NETWORK_STRUCT_END _Pragma("pack(pop)")
-
-#else
-#error gcc 4.x or higher required on W32 systems
-#endif
-#else
/**
* Define as empty, GNUNET_PACKED should suffice, but this won't work on W32
*/
@@ -247,7 +218,6 @@ extern "C" {
* Define as empty, GNUNET_PACKED should suffice, but this won't work on W32;
*/
#define GNUNET_NETWORK_STRUCT_END
-#endif
/* ************************ super-general types *********************** */
diff --git a/src/include/tap-windows.h b/src/include/tap-windows.h
deleted file mode 100644
index 37f4129c0..000000000
--- a/src/include/tap-windows.h
+++ /dev/null
@@ -1,81 +0,0 @@
-/*
- * TAP-Windows -- A kernel driver to provide virtual tap
- * device functionality on Windows.
- *
- * This code was inspired by the CIPE-Win32 driver by Damion K. Wilson.
- *
- * This source code is Copyright Copyright (C) 2002-2010 OpenVPN Technologies, Inc.,
- * and is released under the GPL version 2 (see below).
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2
- * as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program (see the file COPYING included with this
- * distribution); if not, write to the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- */
-/**
- * @file
- * TAP32 virtual network driver defines
- *
- * @attention This file is part of openvpn and for kept
- * as a separate file to allow easier upgrading.
- */
-#ifndef __TAP_WIN_H
-#define __TAP_WIN_H
-
-/*
- * =============
- * TAP IOCTLs
- * =============
- */
-
-#define TAP_WIN_CONTROL_CODE(request, method) \
- CTL_CODE(FILE_DEVICE_UNKNOWN, request, method, FILE_ANY_ACCESS)
-
-/* Present in 8.1 */
-
-#define TAP_WIN_IOCTL_GET_MAC TAP_WIN_CONTROL_CODE(1, METHOD_BUFFERED)
-#define TAP_WIN_IOCTL_GET_VERSION TAP_WIN_CONTROL_CODE(2, METHOD_BUFFERED)
-#define TAP_WIN_IOCTL_GET_MTU TAP_WIN_CONTROL_CODE(3, METHOD_BUFFERED)
-#define TAP_WIN_IOCTL_GET_INFO TAP_WIN_CONTROL_CODE(4, METHOD_BUFFERED)
-#define TAP_WIN_IOCTL_CONFIG_POINT_TO_POINT TAP_WIN_CONTROL_CODE(5, METHOD_BUFFERED)
-#define TAP_WIN_IOCTL_SET_MEDIA_STATUS TAP_WIN_CONTROL_CODE(6, METHOD_BUFFERED)
-#define TAP_WIN_IOCTL_CONFIG_DHCP_MASQ TAP_WIN_CONTROL_CODE(7, METHOD_BUFFERED)
-#define TAP_WIN_IOCTL_GET_LOG_LINE TAP_WIN_CONTROL_CODE(8, METHOD_BUFFERED)
-#define TAP_WIN_IOCTL_CONFIG_DHCP_SET_OPT TAP_WIN_CONTROL_CODE(9, METHOD_BUFFERED)
-
-/* Added in 8.2 */
-
-/* obsoletes TAP_WIN_IOCTL_CONFIG_POINT_TO_POINT */
-#define TAP_WIN_IOCTL_CONFIG_TUN TAP_WIN_CONTROL_CODE(10, METHOD_BUFFERED)
-
-/*
- * =================
- * Registry keys
- * =================
- */
-
-#define ADAPTER_KEY "SYSTEM\\CurrentControlSet\\Control\\Class\\{4D36E972-E325-11CE-BFC1-08002BE10318}"
-
-#define NETWORK_CONNECTIONS_KEY "SYSTEM\\CurrentControlSet\\Control\\Network\\{4D36E972-E325-11CE-BFC1-08002BE10318}"
-
-/*
- * ======================
- * Filesystem prefixes
- * ======================
- */
-
-#define USERMODEDEVICEDIR "\\\\.\\Global\\"
-#define SYSDEVICEDIR "\\Device\\"
-#define USERDEVICEDIR "\\DosDevices\\Global\\"
-#define TAP_WIN_SUFFIX ".tap"
-
-#endif
diff --git a/src/include/winproc.h b/src/include/winproc.h
deleted file mode 100644
index 139f07e61..000000000
--- a/src/include/winproc.h
+++ /dev/null
@@ -1,235 +0,0 @@
-/*
- This file is part of GNUnet.
- Copyright (C) 2001, 2002, 2003, 2004, 2005 GNUnet e.V.
-
- GNUnet is free software: you can redistribute it and/or modify it
- under the terms of the GNU Affero General Public License as published
- by the Free Software Foundation, either version 3 of the License,
- or (at your option) any later version.
-
- GNUnet is distributed in the hope that it will be useful, but
- WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- Affero General Public License for more details.
-
- You should have received a copy of the GNU Affero General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>.
-
- SPDX-License-Identifier: AGPL3.0-or-later
- */
-
-/**
- * @author Nils Durner
- *
- * @file
- * Definitions for MS Windows
- */
-
-#ifndef _WINPROC_H
-#define _WINPROC_H
-
-#include <io.h>
-#include <stdio.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <sys/timeb.h>
-#include <time.h>
-#include <dirent.h>
-#ifndef FD_SETSIZE
-#define FD_SETSIZE 1024
-#endif
-#include <winsock2.h>
-#include <ws2tcpip.h>
-#include <windows.h>
-#include <winerror.h>
-#include <iphlpapi.h>
-#include <shlobj.h>
-#include <objbase.h>
-#include <sys/param.h> /* #define BYTE_ORDER */
-#include <ntsecapi.h>
-#include <lm.h>
-#include <aclapi.h>
-
-
-#ifdef __cplusplus
-extern "C"
-{
-#endif
-
-#ifndef MAX_NAME_LENGTH
-#define MAX_NAME_LENGTH 25
-#endif
-
-typedef DWORD WINAPI (*TNtQuerySystemInformation) (int, PVOID, ULONG, PULONG);
-typedef DWORD WINAPI (*TGetIfEntry) (PMIB_IFROW pIfRow);
-typedef DWORD WINAPI (*TGetIpAddrTable) (PMIB_IPADDRTABLE pIpAddrTable,
- PULONG pdwSize, BOOL bOrder);
-typedef DWORD WINAPI (*TGetIfTable) (PMIB_IFTABLE pIfTable, PULONG pdwSize,
- BOOL bOrder);
-typedef DWORD WINAPI (*TGetBestInterfaceEx) (struct sockaddr *, PDWORD);
-/* TODO: Explicitly import -A variants (i.e. TCreateHardLinkA) or -W
- * variants (TCreateHardLinkW), etc.
- */
-typedef DWORD WINAPI (*TCreateHardLink) (LPCTSTR lpFileName,
- LPCTSTR lpExistingFileName,
- LPSECURITY_ATTRIBUTES
- lpSecurityAttributes);
-typedef SC_HANDLE WINAPI (*TOpenSCManager) (LPCTSTR lpMachineName,
- LPCTSTR lpDatabaseName,
- DWORD dwDesiredAccess);
-typedef SC_HANDLE WINAPI (*TCreateService) (SC_HANDLE hSCManager,
- LPCTSTR lpServiceName,
- LPCTSTR lpDisplayName,
- DWORD dwDesiredAccess,
- DWORD dwServiceType,
- DWORD dwStartType,
- DWORD dwErrorControl,
- LPCTSTR lpBinaryPathName,
- LPCTSTR lpLoadOrderGroup,
- LPDWORD lpdwTagId,
- LPCTSTR lpDependencies,
- LPCTSTR lpServiceStartName,
- LPCTSTR lpPassword);
-typedef BOOL WINAPI (*TCloseServiceHandle) (SC_HANDLE hSCObject);
-typedef BOOL WINAPI (*TDeleteService) (SC_HANDLE hService);
-typedef SERVICE_STATUS_HANDLE WINAPI (*TRegisterServiceCtrlHandler) (LPCTSTR
- lpServiceName,
- LPHANDLER_FUNCTION
- lpHandlerProc);
-typedef BOOL WINAPI (*TSetServiceStatus) (SERVICE_STATUS_HANDLE
- hServiceStatus,
- LPSERVICE_STATUS lpServiceStatus);
-typedef BOOL WINAPI (*TStartServiceCtrlDispatcher) (const
- LPSERVICE_TABLE_ENTRY
- lpServiceTable);
-typedef BOOL WINAPI (*TControlService) (SC_HANDLE hService, DWORD dwControl,
- LPSERVICE_STATUS lpServiceStatus);
-typedef SC_HANDLE WINAPI (*TOpenService) (SC_HANDLE hSCManager,
- LPCTSTR lpServiceName,
- DWORD dwDesiredAccess);
-typedef DWORD WINAPI (*TGetAdaptersInfo) (PIP_ADAPTER_INFO pAdapterInfo,
- PULONG pOutBufLen);
-typedef NET_API_STATUS WINAPI (*TNetUserAdd) (LPCWSTR, DWORD, PBYTE, PDWORD);
-typedef NET_API_STATUS WINAPI (*TNetUserSetInfo) (LPCWSTR servername,
- LPCWSTR username,
- DWORD level, LPBYTE buf,
- LPDWORD param_err);
-typedef NTSTATUS NTAPI (*TLsaOpenPolicy) (PLSA_UNICODE_STRING,
- PLSA_OBJECT_ATTRIBUTES, ACCESS_MASK,
- PLSA_HANDLE);
-typedef NTSTATUS NTAPI (*TLsaAddAccountRights) (LSA_HANDLE, PSID,
- PLSA_UNICODE_STRING, ULONG);
-typedef NTSTATUS NTAPI (*TLsaRemoveAccountRights) (LSA_HANDLE, PSID, BOOLEAN,
- PLSA_UNICODE_STRING,
- ULONG);
-typedef NTSTATUS NTAPI (*TLsaClose) (LSA_HANDLE);
-typedef BOOL WINAPI (*TLookupAccountName) (LPCTSTR lpSystemName,
- LPCTSTR lpAccountName, PSID Sid,
- LPDWORD cbSid,
- LPTSTR ReferencedDomainName,
- LPDWORD cchReferencedDomainName,
- PSID_NAME_USE peUse);
-
-typedef BOOL WINAPI (*TGetFileSecurity) (LPCTSTR lpFileName,
- SECURITY_INFORMATION
- RequestedInformation,
- PSECURITY_DESCRIPTOR
- pSecurityDescriptor, DWORD nLength,
- LPDWORD lpnLengthNeeded);
-typedef BOOL WINAPI (*TInitializeSecurityDescriptor) (PSECURITY_DESCRIPTOR
- pSecurityDescriptor,
- DWORD dwRevision);
-typedef BOOL WINAPI (*TGetSecurityDescriptorDacl) (PSECURITY_DESCRIPTOR
- pSecurityDescriptor,
- LPBOOL lpbDaclPresent,
- PACL * pDacl,
- LPBOOL lpbDaclDefaulted);
-typedef BOOL WINAPI (*TGetAclInformation) (PACL pAcl, LPVOID pAclInformation,
- DWORD nAclInformationLength,
- ACL_INFORMATION_CLASS
- dwAclInformationClass);
-typedef BOOL WINAPI (*TInitializeAcl) (PACL pAcl, DWORD nAclLength,
- DWORD dwAclRevision);
-typedef BOOL WINAPI (*TGetAce) (PACL pAcl, DWORD dwAceIndex, LPVOID * pAce);
-typedef BOOL WINAPI (*TEqualSid) (PSID pSid1, PSID pSid2);
-typedef BOOL WINAPI (*TAddAce) (PACL pAcl, DWORD dwAceRevision,
- DWORD dwStartingAceIndex, LPVOID pAceList,
- DWORD nAceListLength);
-typedef BOOL WINAPI (*TAddAccessAllowedAce) (PACL pAcl, DWORD dwAceRevision,
- DWORD AccessMask, PSID pSid);
-typedef BOOL WINAPI (*TSetNamedSecurityInfo) (LPTSTR pObjectName,
- SE_OBJECT_TYPE ObjectType,
- SECURITY_INFORMATION
- SecurityInfo, PSID psidOwner,
- PSID psidGroup, PACL pDacl,
- PACL pSacl);
-
-extern TGetBestInterfaceEx GNGetBestInterfaceEx;
-extern TNtQuerySystemInformation GNNtQuerySystemInformation;
-extern TGetIfEntry GNGetIfEntry;
-extern TGetIpAddrTable GNGetIpAddrTable;
-extern TGetIfTable GNGetIfTable;
-extern TCreateHardLink GNCreateHardLink;
-extern TOpenSCManager GNOpenSCManager;
-extern TCreateService GNCreateService;
-extern TCloseServiceHandle GNCloseServiceHandle;
-extern TDeleteService GNDeleteService;
-extern TRegisterServiceCtrlHandler GNRegisterServiceCtrlHandler;
-extern TSetServiceStatus GNSetServiceStatus;
-extern TStartServiceCtrlDispatcher GNStartServiceCtrlDispatcher;
-extern TControlService GNControlService;
-extern TOpenService GNOpenService;
-extern TGetAdaptersInfo GNGetAdaptersInfo;
-extern TNetUserAdd GNNetUserAdd;
-extern TNetUserSetInfo GNNetUserSetInfo;
-extern TLsaOpenPolicy GNLsaOpenPolicy;
-extern TLsaAddAccountRights GNLsaAddAccountRights;
-extern TLsaRemoveAccountRights GNLsaRemoveAccountRights;
-extern TLsaClose GNLsaClose;
-extern TLookupAccountName GNLookupAccountName;
-extern TGetFileSecurity GNGetFileSecurity;
-extern TInitializeSecurityDescriptor GNInitializeSecurityDescriptor;
-extern TGetSecurityDescriptorDacl GNGetSecurityDescriptorDacl;
-extern TGetAclInformation GNGetAclInformation;
-extern TInitializeAcl GNInitializeAcl;
-extern TGetAce GNGetAce;
-extern TEqualSid GNEqualSid;
-extern TAddAce GNAddAce;
-extern TAddAccessAllowedAce GNAddAccessAllowedAce;
-extern TSetNamedSecurityInfo GNSetNamedSecurityInfo;
-
-
-BOOL CreateShortcut(const char *pszSrc, const char *pszDest);
-BOOL DereferenceShortcut(char *pszShortcut);
-long QueryRegistry(HKEY hMainKey, const char *pszKey, const char *pszSubKey,
- char *pszBuffer, long *pdLength);
-int ListNICs(void (*callback)(void *, const char *, int), void *cls);
-BOOL AddPathAccessRights(char *lpszFileName, char *lpszAccountName,
- DWORD dwAccessMask);
-char *winErrorStr(const char *prefix, int dwErr);
-void EnumNICs(PMIB_IFTABLE * pIfTable, PMIB_IPADDRTABLE * pAddrTable);
-
-#define ENUMNICS3_MASK_OK 0x01
-#define ENUMNICS3_BCAST_OK 0x02
-
-struct EnumNICs3_results {
- unsigned char flags;
- int is_default;
- char pretty_name[1001];
- size_t addr_size;
- SOCKADDR_STORAGE address;
- SOCKADDR_STORAGE mask;
- SOCKADDR_STORAGE broadcast;
-};
-
-int EnumNICs3(struct EnumNICs3_results **, int *EnumNICs3_results_count);
-void EnumNICs3_free(struct EnumNICs3_results *);
-int GNInitWinEnv();
-void GNShutdownWinEnv();
-
-BOOL SafeTerminateProcess(HANDLE hProcess, UINT uExitCode, DWORD dwTimeout);
-#ifdef __cplusplus
-}
-#endif
-
-#endif
diff --git a/src/integration-tests/Makefile.am b/src/integration-tests/Makefile.am
index 26dd4f92d..8b50def4d 100644
--- a/src/integration-tests/Makefile.am
+++ b/src/integration-tests/Makefile.am
@@ -1,10 +1,6 @@
# This Makefile.am is in the public domain
AM_CPPFLAGS = -I$(top_srcdir)/src/include
-if MINGW
- WINFLAGS = -Wl,--no-undefined -Wl,--export-all-symbols
-endif
-
if USE_COVERAGE
AM_CFLAGS = --coverage -O0
XLIB = -lgcov
diff --git a/src/my/Makefile.am b/src/my/Makefile.am
index cead9a8b4..51e20e6bf 100644
--- a/src/my/Makefile.am
+++ b/src/my/Makefile.am
@@ -1,10 +1,6 @@
# This Makefile.am is in the public domain
AM_CPPFLAGS = -I$(top_srcdir)/src/include
-if MINGW
- WINFLAGS = -Wl,--no-undefined -Wl,--export-all-symbols
-endif
-
if USE_COVERAGE
AM_CFLAGS = --coverage
endif
diff --git a/src/mysql/Makefile.am b/src/mysql/Makefile.am
index 889562d60..3bfb929cd 100644
--- a/src/mysql/Makefile.am
+++ b/src/mysql/Makefile.am
@@ -1,10 +1,6 @@
# This Makefile.am is in the public domain
AM_CPPFLAGS = -I$(top_srcdir)/src/include
-if MINGW
- WINFLAGS = -Wl,--no-undefined -Wl,--export-all-symbols
-endif
-
if USE_COVERAGE
AM_CFLAGS = --coverage
endif
diff --git a/src/namecache/Makefile.am b/src/namecache/Makefile.am
index c62ca6a2b..8abae68a4 100644
--- a/src/namecache/Makefile.am
+++ b/src/namecache/Makefile.am
@@ -10,11 +10,6 @@ libexecdir= $(pkglibdir)/libexec/
pkgcfg_DATA = \
namecache.conf
-
-if MINGW
- WINFLAGS = -Wl,--no-undefined -Wl,--export-all-symbols
-endif
-
if USE_COVERAGE
AM_CFLAGS = --coverage -O0
XLIBS = -lgcov
diff --git a/src/namestore/Makefile.am b/src/namestore/Makefile.am
index ad99a3f0b..b9fa83103 100644
--- a/src/namestore/Makefile.am
+++ b/src/namestore/Makefile.am
@@ -10,11 +10,6 @@ libexecdir= $(pkglibdir)/libexec/
pkgcfg_DATA = \
namestore.conf
-
-if MINGW
- WINFLAGS = -Wl,--no-undefined -Wl,--export-all-symbols
-endif
-
if USE_COVERAGE
AM_CFLAGS = --coverage -O0
XLIBS = -lgcov
diff --git a/src/nat/Makefile.am b/src/nat/Makefile.am
index f0d5639a1..db104d194 100644
--- a/src/nat/Makefile.am
+++ b/src/nat/Makefile.am
@@ -1,13 +1,6 @@
# This Makefile.am is in the public domain
AM_CPPFLAGS = -I$(top_srcdir)/src/include
-if MINGW
- WINFLAGS = -Wl,--no-undefined -Wl,--export-all-symbols
- NATBIN = gnunet-helper-nat-server gnunet-helper-nat-client
- NATSERVER = gnunet-helper-nat-server-windows.c
- NATCLIENT = gnunet-helper-nat-client-windows.c
-endif
-
libexecdir= $(pkglibdir)/libexec/
pkgcfgdir= $(pkgdatadir)/config.d/
@@ -45,7 +38,7 @@ gnunet_helper_nat_server_SOURCES = \
$(NATSERVER)
gnunet_helper_nat_client_SOURCES = \
- $(NATCLIENT)
+ $(NATCLIENT)
gnunet_nat_SOURCES = \
diff --git a/src/nat/gnunet-helper-nat-client-windows.c b/src/nat/gnunet-helper-nat-client-windows.c
deleted file mode 100644
index 1be31ae42..000000000
--- a/src/nat/gnunet-helper-nat-client-windows.c
+++ /dev/null
@@ -1,529 +0,0 @@
-/*
- This file is part of GNUnet.
- Copyright (C) 2010 GNUnet e.V.
-
- GNUnet is free software: you can redistribute it and/or modify it
- under the terms of the GNU Affero General Public License as published
- by the Free Software Foundation, either version 3 of the License,
- or (at your option) any later version.
-
- GNUnet is distributed in the hope that it will be useful, but
- WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- Affero General Public License for more details.
-
- You should have received a copy of the GNU Affero General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>.
-
- SPDX-License-Identifier: AGPL3.0-or-later
- */
-
-/**
- * @file src/nat/gnunet-helper-nat-client-windows.c
- * @brief Tool to help bypass NATs using ICMP method; must run as
- * administrator on W32
- * This code is for W32.
- * @author Nathan Evans
- *
- * This program will send ONE ICMP message using RAW sockets
- * to the IP address specified as the second argument. Since
- * it uses RAW sockets, it must be installed SUID or run as 'root'.
- * In order to keep the security risk of the resulting SUID binary
- * minimal, the program ONLY opens the RAW socket with root
- * privileges, then drops them and only then starts to process
- * command line arguments. The code also does not link against
- * any shared libraries (except libc) and is strictly minimal
- * (except for checking for errors). The following list of people
- * have reviewed this code and considered it safe since the last
- * modification (if you reviewed it, please have your name added
- * to the list):
- *
- * - Christian Grothoff
- * - Nathan Evans
- */
-#define _GNU_SOURCE
-/* Instead of including gnunet_common.h */
-#define GNUNET_memcpy(dst, src, n) do { if (0 != n) { (void)memcpy(dst, src, n); } } while (0)
-
-#define FD_SETSIZE 1024
-#include <winsock2.h>
-#include <ws2tcpip.h>
-#include <sys/time.h>
-#include <sys/types.h>
-#include <unistd.h>
-#include <stdio.h>
-#include <string.h>
-#include <errno.h>
-#include <stdlib.h>
-#include <stdint.h>
-#include <time.h>
-
-
-#define ICMP_ECHO 8
-#define IPDEFTTL 64
-#define ICMP_TIME_EXCEEDED 11
-
-/**
- * Must match IP given in the server.
- */
-#define DUMMY_IP "192.0.2.86"
-
-#define NAT_TRAV_PORT 22225
-
-/**
- * IPv4 header.
- */
-struct ip_header {
- /**
- * Version (4 bits) + Internet header length (4 bits)
- */
- uint8_t vers_ihl;
-
- /**
- * Type of service
- */
- uint8_t tos;
-
- /**
- * Total length
- */
- uint16_t pkt_len;
-
- /**
- * Identification
- */
- uint16_t id;
-
- /**
- * Flags (3 bits) + Fragment offset (13 bits)
- */
- uint16_t flags_frag_offset;
-
- /**
- * Time to live
- */
- uint8_t ttl;
-
- /**
- * Protocol
- */
- uint8_t proto;
-
- /**
- * Header checksum
- */
- uint16_t checksum;
-
- /**
- * Source address
- */
- uint32_t src_ip;
-
- /**
- * Destination address
- */
- uint32_t dst_ip;
-};
-
-
-/**
- * Format of ICMP packet.
- */
-struct icmp_ttl_exceeded_header {
- uint8_t type;
-
- uint8_t code;
-
- uint16_t checksum;
-
- uint32_t unused;
-
- /* followed by original payload */
-};
-
-struct icmp_echo_header {
- uint8_t type;
-
- uint8_t code;
-
- uint16_t checksum;
-
- uint32_t reserved;
-};
-
-/**
- * Beginning of UDP packet.
- */
-struct udp_header {
- uint16_t src_port;
-
- uint16_t dst_port;
-
- uint16_t length;
-
- uint16_t crc;
-};
-
-/**
- * Will this binary be run in permissions testing mode?
- */
-static boolean privilege_testing = FALSE;
-
-/**
- * Socket we use to send our ICMP packets.
- */
-static _win_socket rawsock;
-
-/**
- * Target "dummy" address.
- */
-static struct in_addr dummy;
-
-/**
- * Port we are listening on (communicated to the server).
- */
-static uint16_t port;
-
-
-
-/**
- * Convert IPv4 address from text to binary form.
- *
- * @param af address family
- * @param cp the address to print
- * @param buf where to write the address result
- * @return 1 on success
- */
-static int
-inet_pton(int af, const char *cp, struct in_addr *buf)
-{
- buf->s_addr = inet_addr(cp);
- if (buf->s_addr == INADDR_NONE)
- {
- fprintf(stderr, "Error %d handling address %s", WSAGetLastError(), cp);
- return 0;
- }
- return 1;
-}
-
-
-/**
- * CRC-16 for IP/ICMP headers.
- *
- * @param data what to calculate the CRC over
- * @param bytes number of bytes in data (must be multiple of 2)
- * @return the CRC 16.
- */
-static uint16_t
-calc_checksum(const uint16_t * data, unsigned int bytes)
-{
- uint32_t sum;
- unsigned int i;
-
- sum = 0;
- for (i = 0; i < bytes / 2; i++)
- sum += data[i];
- sum = (sum & 0xffff) + (sum >> 16);
- sum = htons(0xffff - sum);
- return sum;
-}
-
-
-/**
- * Send an ICMP message to the target.
- *
- * @param my_ip source address
- * @param other target address
- */
-static void
-send_icmp_udp(const struct in_addr *my_ip, const struct in_addr *other)
-{
- char packet[sizeof(struct ip_header) * 2 +
- sizeof(struct icmp_ttl_exceeded_header) +
- sizeof(struct udp_header)];
- struct ip_header ip_pkt;
- struct icmp_ttl_exceeded_header icmp_pkt;
- struct udp_header udp_pkt;
- struct sockaddr_in dst;
- size_t off;
- int err;
-
- /* ip header: send to (known) ip address */
- off = 0;
- ip_pkt.vers_ihl = 0x45;
- ip_pkt.tos = 0;
- ip_pkt.pkt_len = htons(sizeof(packet));
- ip_pkt.id = htons(256);
- ip_pkt.flags_frag_offset = 0;
- ip_pkt.ttl = 128;
- ip_pkt.proto = IPPROTO_ICMP;
- ip_pkt.checksum = 0;
- ip_pkt.src_ip = my_ip->s_addr;
- ip_pkt.dst_ip = other->s_addr;
- ip_pkt.checksum =
- htons(calc_checksum((uint16_t *)&ip_pkt, sizeof(struct ip_header)));
- GNUNET_memcpy(&packet[off], &ip_pkt, sizeof(struct ip_header));
- off += sizeof(struct ip_header);
-
- icmp_pkt.type = ICMP_TIME_EXCEEDED;
- icmp_pkt.code = 0;
- icmp_pkt.checksum = 0;
- icmp_pkt.unused = 0;
- GNUNET_memcpy(&packet[off], &icmp_pkt, sizeof(struct icmp_ttl_exceeded_header));
- off += sizeof(struct icmp_ttl_exceeded_header);
-
- /* ip header of the presumably 'lost' udp packet */
- ip_pkt.vers_ihl = 0x45;
- ip_pkt.tos = 0;
- ip_pkt.pkt_len =
- htons(sizeof(struct ip_header) + sizeof(struct udp_header));
- ip_pkt.id = htons(0);
- ip_pkt.flags_frag_offset = 0;
- ip_pkt.ttl = 128;
- ip_pkt.proto = IPPROTO_UDP;
- ip_pkt.checksum = 0;
- ip_pkt.src_ip = other->s_addr;
- ip_pkt.dst_ip = dummy.s_addr;
- ip_pkt.checksum =
- htons(calc_checksum((uint16_t *)&ip_pkt, sizeof(struct ip_header)));
- GNUNET_memcpy(&packet[off], &ip_pkt, sizeof(struct ip_header));
- off += sizeof(struct ip_header);
-
- /* build UDP header */
- udp_pkt.src_port = htons(NAT_TRAV_PORT);
- udp_pkt.dst_port = htons(NAT_TRAV_PORT);
- udp_pkt.length = htons(port);
- udp_pkt.crc = 0;
- GNUNET_memcpy(&packet[off], &udp_pkt, sizeof(struct udp_header));
- off += sizeof(struct udp_header);
-
- /* no go back to calculate ICMP packet checksum */
- icmp_pkt.checksum =
- htons(calc_checksum
- ((uint16_t *)&packet[off],
- sizeof(struct icmp_ttl_exceeded_header) +
- sizeof(struct ip_header) + sizeof(struct udp_header)));
- GNUNET_memcpy(&packet[sizeof(struct ip_header)], &icmp_pkt,
- sizeof(struct icmp_ttl_exceeded_header));
-
- memset(&dst, 0, sizeof(dst));
- dst.sin_family = AF_INET;
- dst.sin_addr = *other;
- err =
- sendto(rawsock, packet, sizeof(packet), 0, (struct sockaddr *)&dst,
- sizeof(dst));
- if (err < 0)
- {
- fprintf(stderr, "sendto failed: %s\n", strerror(errno));
- }
- else if (sizeof(packet) != (size_t)err)
- {
- fprintf(stderr, "Error: partial send of ICMP message\n");
- }
-}
-
-
-/**
- * Send an ICMP message to the target.
- *
- * @param my_ip source address
- * @param other target address
- */
-static void
-send_icmp(const struct in_addr *my_ip, const struct in_addr *other)
-{
- struct ip_header ip_pkt;
- struct icmp_ttl_exceeded_header icmp_ttl;
- struct icmp_echo_header icmp_echo;
- struct sockaddr_in dst;
- char packet[sizeof(struct ip_header) * 2 +
- sizeof(struct icmp_ttl_exceeded_header) +
- sizeof(struct icmp_echo_header)];
- size_t off;
- int err;
-
- /* ip header: send to (known) ip address */
- off = 0;
- ip_pkt.vers_ihl = 0x45;
- ip_pkt.tos = 0;
- ip_pkt.pkt_len = htons(sizeof(packet));
- ip_pkt.id = htons(256);
- ip_pkt.flags_frag_offset = 0;
- ip_pkt.ttl = IPDEFTTL;
- ip_pkt.proto = IPPROTO_ICMP;
- ip_pkt.checksum = 0;
- ip_pkt.src_ip = my_ip->s_addr;
- ip_pkt.dst_ip = other->s_addr;
- ip_pkt.checksum =
- htons(calc_checksum((uint16_t *)&ip_pkt, sizeof(struct ip_header)));
- GNUNET_memcpy(&packet[off], &ip_pkt, sizeof(struct ip_header));
- off += sizeof(ip_pkt);
-
- /* icmp reply: time exceeded */
- icmp_ttl.type = ICMP_TIME_EXCEEDED;
- icmp_ttl.code = 0;
- icmp_ttl.checksum = 0;
- icmp_ttl.unused = 0;
- GNUNET_memcpy(&packet[off], &icmp_ttl, sizeof(struct icmp_ttl_exceeded_header));
- off += sizeof(struct icmp_ttl_exceeded_header);
-
- /* ip header of the presumably 'lost' udp packet */
- ip_pkt.vers_ihl = 0x45;
- ip_pkt.tos = 0;
- ip_pkt.pkt_len =
- htons(sizeof(struct ip_header) + sizeof(struct icmp_echo_header));
- ip_pkt.id = htons(256);
- ip_pkt.flags_frag_offset = 0;
- ip_pkt.ttl = 1; /* real TTL would be 1 on a time exceeded packet */
- ip_pkt.proto = IPPROTO_ICMP;
- ip_pkt.src_ip = other->s_addr;
- ip_pkt.dst_ip = dummy.s_addr;
- ip_pkt.checksum = 0;
- ip_pkt.checksum =
- htons(calc_checksum((uint16_t *)&ip_pkt, sizeof(struct ip_header)));
- GNUNET_memcpy(&packet[off], &ip_pkt, sizeof(struct ip_header));
- off += sizeof(struct ip_header);
-
- icmp_echo.type = ICMP_ECHO;
- icmp_echo.code = 0;
- icmp_echo.reserved = htonl(port);
- icmp_echo.checksum = 0;
- icmp_echo.checksum =
- htons(calc_checksum
- ((uint16_t *)&icmp_echo, sizeof(struct icmp_echo_header)));
- GNUNET_memcpy(&packet[off], &icmp_echo, sizeof(struct icmp_echo_header));
-
- /* no go back to calculate ICMP packet checksum */
- off = sizeof(struct ip_header);
- icmp_ttl.checksum =
- htons(calc_checksum
- ((uint16_t *)&packet[off],
- sizeof(struct icmp_ttl_exceeded_header) +
- sizeof(struct ip_header) + sizeof(struct icmp_echo_header)));
- GNUNET_memcpy(&packet[off], &icmp_ttl, sizeof(struct icmp_ttl_exceeded_header));
-
- memset(&dst, 0, sizeof(dst));
- dst.sin_family = AF_INET;
- dst.sin_addr = *other;
-
- err =
- sendto(rawsock, packet, sizeof(packet), 0, (struct sockaddr *)&dst,
- sizeof(dst));
-
- if (err < 0)
- {
- fprintf(stderr, "sendto failed: %s\n", strerror(errno));
- }
- else if (sizeof(packet) != (size_t)err)
- {
- fprintf(stderr, "Error: partial send of ICMP message\n");
- }
-}
-
-
-/**
- * Create an ICMP raw socket.
- *
- * @return INVALID_SOCKET on error
- */
-static _win_socket
-make_raw_socket()
-{
- DWORD bOptVal = TRUE;
- int bOptLen = sizeof(bOptVal);
- _win_socket ret;
-
- ret = _win_socket(AF_INET, SOCK_RAW, IPPROTO_RAW);
- if (INVALID_SOCKET == ret)
- {
- fprintf(stderr, "Error opening RAW socket: %s\n", strerror(errno));
- return INVALID_SOCKET;
- }
- if (0 !=
- _win_setsockopt(ret, SOL_SOCKET, SO_BROADCAST, (char *)&bOptVal, bOptLen))
- {
- fprintf(stderr, "Error setting SO_BROADCAST to ON: %s\n",
- strerror(errno));
- closesocket(rawsock);
- return INVALID_SOCKET;
- }
-
- if (0 != _win_setsockopt(ret, IPPROTO_IP, IP_HDRINCL, (char *)&bOptVal, bOptLen))
- {
- fprintf(stderr, "Error setting IP_HDRINCL to ON: %s\n", strerror(errno));
- closesocket(rawsock);
- return INVALID_SOCKET;
- }
- return ret;
-}
-
-
-int
-main(int argc, char *const *argv)
-{
- struct in_addr external;
- struct in_addr target;
- WSADATA wsaData;
- unsigned int p;
-
- if (argc > 1 && 0 != strcmp(argv[1], "-d"))
- {
- privilege_testing = TRUE;
- fprintf(stderr,
- "%s",
- "DEBUG: Running binary in privilege testing mode.");
- argv++;
- argc--;
- }
-
- if (argc != 4)
- {
- fprintf(stderr,
- "%s",
- "This program must be started with our IP, the targets external IP, and our port as arguments.\n");
- return 1;
- }
- if ((1 != inet_pton(AF_INET, argv[1], &external)) ||
- (1 != inet_pton(AF_INET, argv[2], &target)))
- {
- fprintf(stderr,
- "Error parsing IPv4 address: %s\n",
- strerror(errno));
- return 1;
- }
- if ((1 != sscanf(argv[3], "%u", &p)) || (0 == p) || (0xFFFF < p))
- {
- fprintf(stderr,
- "Error parsing port value `%s'\n",
- argv[3]);
- return 1;
- }
- port = (uint16_t)p;
-
- if (0 != WSAStartup(MAKEWORD(2, 1), &wsaData))
- {
- fprintf(stderr,
- "%s",
- "Failed to find Winsock 2.1 or better.\n");
- return 2;
- }
- if (1 != inet_pton(AF_INET, DUMMY_IP, &dummy))
- {
- fprintf(stderr,
- "%s",
- "Internal error converting dummy IP to binary.\n");
- return 2;
- }
- if (-1 == (rawsock = make_raw_socket()))
- return 3;
- if (!privilege_testing)
- {
- send_icmp(&external, &target);
- send_icmp_udp(&external, &target);
- }
- closesocket(rawsock);
- WSACleanup();
- return 0;
-}
-
-/* end of gnunet-helper-nat-client-windows.c */
diff --git a/src/nat/gnunet-helper-nat-server-windows.c b/src/nat/gnunet-helper-nat-server-windows.c
deleted file mode 100644
index 688dde165..000000000
--- a/src/nat/gnunet-helper-nat-server-windows.c
+++ /dev/null
@@ -1,614 +0,0 @@
-/*
- This file is part of GNUnet.
- Copyright (C) 2010 GNUnet e.V.
-
- GNUnet is free software: you can redistribute it and/or modify it
- under the terms of the GNU Affero General Public License as published
- by the Free Software Foundation, either version 3 of the License,
- or (at your option) any later version.
-
- GNUnet is distributed in the hope that it will be useful, but
- WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- Affero General Public License for more details.
-
- You should have received a copy of the GNU Affero General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>.
-
- SPDX-License-Identifier: AGPL3.0-or-later
- */
-
-/**
- * @file src/nat/gnunet-helper-nat-server-windows.c
- * @brief Windows tool to help bypass NATs using ICMP method
- * This code will work under W32 only
- * @author Christian Grothoff
- *
- * This program will send ONE ICMP message every 500 ms RAW sockets
- * to a DUMMY IP address and also listens for ICMP replies. Since
- * it uses RAW sockets, it must be run as an administrative user.
- * In order to keep the security risk of the resulting binary
- * minimal, the program ONLY opens the two RAW sockets with administrative
- * privileges, then drops them and only then starts to process
- * command line arguments. The code also does not link against
- * any shared libraries (except libc) and is strictly minimal
- * (except for checking for errors). The following list of people
- * have reviewed this code and considered it safe since the last
- * modification (if you reviewed it, please have your name added
- * to the list):
- *
- * - Nathan Evans
- * - Christian Grothoff
- */
-#define _GNU_SOURCE
-/* Instead of including gnunet_common.h */
-#define GNUNET_memcpy(dst, src, n) do { if (0 != n) { (void)memcpy(dst, src, n); } } while (0)
-
-#define FD_SETSIZE 1024
-#include <winsock2.h>
-#include <ws2tcpip.h>
-#include <sys/time.h>
-#include <sys/types.h>
-#include <unistd.h>
-#include <stdio.h>
-#include <string.h>
-#include <errno.h>
-#include <stdlib.h>
-#include <stdint.h>
-#include <time.h>
-
-/**
- * Should we print some debug output?
- */
-#define VERBOSE 0
-
-/**
- * Must match IP given in the client.
- */
-#define DUMMY_IP "192.0.2.86"
-
-/**
- * Default Port
- */
-#define NAT_TRAV_PORT 22225
-
-/**
- * Must match packet ID used by gnunet-helper-nat-client.c
- */
-#define PACKET_ID 256
-
-/**
- * TTL to use for our outgoing messages.
- */
-#define IPDEFTTL 64
-
-#define ICMP_ECHO 8
-
-#define ICMP_TIME_EXCEEDED 11
-
-/**
- * How often do we send our ICMP messages to receive replies?
- */
-#define ICMP_SEND_FREQUENCY_MS 500
-
-/**
- * IPv4 header.
- */
-struct ip_header {
- /**
- * Version (4 bits) + Internet header length (4 bits)
- */
- uint8_t vers_ihl;
-
- /**
- * Type of service
- */
- uint8_t tos;
-
- /**
- * Total length
- */
- uint16_t pkt_len;
-
- /**
- * Identification
- */
- uint16_t id;
-
- /**
- * Flags (3 bits) + Fragment offset (13 bits)
- */
- uint16_t flags_frag_offset;
-
- /**
- * Time to live
- */
- uint8_t ttl;
-
- /**
- * Protocol
- */
- uint8_t proto;
-
- /**
- * Header checksum
- */
- uint16_t checksum;
-
- /**
- * Source address
- */
- uint32_t src_ip;
-
- /**
- * Destination address
- */
- uint32_t dst_ip;
-};
-
-/**
- * Format of ICMP packet.
- */
-struct icmp_ttl_exceeded_header {
- uint8_t type;
-
- uint8_t code;
-
- uint16_t checksum;
-
- uint32_t unused;
-
- /* followed by original payload */
-};
-
-struct icmp_echo_header {
- uint8_t type;
-
- uint8_t code;
-
- uint16_t checksum;
-
- uint32_t reserved;
-};
-
-/**
- * Beginning of UDP packet.
- */
-struct udp_header {
- uint16_t src_port;
-
- uint16_t dst_port;
-
- uint16_t length;
-
- uint16_t crc;
-};
-
-/**
- * Will this binary be run in permissions testing mode?
- */
-static boolean privilege_testing = FALSE;
-
-/**
- * Socket we use to receive "fake" ICMP replies.
- */
-static _win_socket icmpsock;
-
-/**
- * Socket we use to send our ICMP requests.
- */
-static _win_socket rawsock;
-
-/**
- * Socket we use to send our UDP requests.
- */
-static _win_socket udpsock;
-
-/**
- * Target "dummy" address.
- */
-static struct in_addr dummy;
-
-
-/**
- * CRC-16 for IP/ICMP headers.
- *
- * @param data what to calculate the CRC over
- * @param bytes number of bytes in data (must be multiple of 2)
- * @return the CRC 16.
- */
-static uint16_t
-calc_checksum(const uint16_t * data, unsigned int bytes)
-{
- uint32_t sum;
- unsigned int i;
-
- sum = 0;
- for (i = 0; i < bytes / 2; i++)
- sum += data[i];
- sum = (sum & 0xffff) + (sum >> 16);
- sum = htons(0xffff - sum);
- return sum;
-}
-
-
-/**
- * Convert IPv4 address from text to binary form.
- *
- * @param af address family
- * @param cp the address to print
- * @param buf where to write the address result
- * @return 1 on success
- */
-static int
-inet_pton(int af, const char *cp, struct in_addr *buf)
-{
- buf->s_addr = inet_addr(cp);
- if (buf->s_addr == INADDR_NONE)
- {
- fprintf(stderr, "Error %d handling address %s", WSAGetLastError(), cp);
- return 0;
- }
- return 1;
-}
-
-
-/**
- * Send an ICMP message to the dummy IP.
- *
- * @param my_ip source address (our ip address)
- */
-static void
-send_icmp_echo(const struct in_addr *my_ip)
-{
- char packet[sizeof(struct ip_header) + sizeof(struct icmp_echo_header)];
- struct icmp_echo_header icmp_echo;
- struct ip_header ip_pkt;
- struct sockaddr_in dst;
- size_t off;
- int err;
-
- off = 0;
- ip_pkt.vers_ihl = 0x45;
- ip_pkt.tos = 0;
- ip_pkt.pkt_len = htons(sizeof(packet));
- ip_pkt.id = htons(PACKET_ID);
- ip_pkt.flags_frag_offset = 0;
- ip_pkt.ttl = IPDEFTTL;
- ip_pkt.proto = IPPROTO_ICMP;
- ip_pkt.checksum = 0;
- ip_pkt.src_ip = my_ip->s_addr;
- ip_pkt.dst_ip = dummy.s_addr;
- ip_pkt.checksum =
- htons(calc_checksum((uint16_t *)&ip_pkt, sizeof(struct ip_header)));
- GNUNET_memcpy(&packet[off], &ip_pkt, sizeof(struct ip_header));
- off += sizeof(struct ip_header);
-
- icmp_echo.type = ICMP_ECHO;
- icmp_echo.code = 0;
- icmp_echo.reserved = 0;
- icmp_echo.checksum = 0;
- icmp_echo.checksum =
- htons(calc_checksum
- ((uint16_t *)&icmp_echo, sizeof(struct icmp_echo_header)));
- GNUNET_memcpy(&packet[off], &icmp_echo, sizeof(struct icmp_echo_header));
- off += sizeof(struct icmp_echo_header);
-
- memset(&dst, 0, sizeof(dst));
- dst.sin_family = AF_INET;
- dst.sin_addr = dummy;
- err =
- sendto(rawsock, packet, off, 0, (struct sockaddr *)&dst, sizeof(dst));
- if (err < 0)
- {
-#if VERBOSE
- fprintf(stderr, "sendto failed: %s\n", strerror(errno));
-#endif
- }
- else if (err != off)
- {
- fprintf(stderr, "Error: partial send of ICMP message\n");
- }
-}
-
-
-/**
- * Send a UDP message to the dummy IP.
- */
-static void
-send_udp()
-{
- struct sockaddr_in dst;
- ssize_t err;
-
- memset(&dst, 0, sizeof(dst));
- dst.sin_family = AF_INET;
- dst.sin_addr = dummy;
- dst.sin_port = htons(NAT_TRAV_PORT);
- err = sendto(udpsock, NULL, 0, 0, (struct sockaddr *)&dst, sizeof(dst));
- if (err < 0)
- {
-#if VERBOSE
- fprintf(stderr, "sendto failed: %s\n", strerror(errno));
-#endif
- }
- else if (0 != err)
- {
- fprintf(stderr, "Error: partial send of ICMP message\n");
- }
-}
-
-
-/**
- * We've received an ICMP response. Process it.
- */
-static void
-process_icmp_response()
-{
- char buf[65536];
- ssize_t have;
- struct in_addr source_ip;
- struct ip_header ip_pkt;
- struct icmp_ttl_exceeded_header icmp_ttl;
- struct icmp_echo_header icmp_echo;
- struct udp_header udp_pkt;
- size_t off;
- uint16_t port;
- DWORD ssize;
-
- have = read(icmpsock, buf, sizeof(buf));
- if (have == -1)
- {
- fprintf(stderr, "Error reading raw socket: %s\n", strerror(errno));
- return;
- }
-#if VERBOSE
- fprintf(stderr, "Received message of %u bytes\n", (unsigned int)have);
-#endif
- if (have <
- (ssize_t)(sizeof(struct ip_header) +
- sizeof(struct icmp_ttl_exceeded_header) +
- sizeof(struct ip_header)))
- {
- /* malformed */
- return;
- }
- off = 0;
- GNUNET_memcpy(&ip_pkt, &buf[off], sizeof(struct ip_header));
- off += sizeof(struct ip_header);
- GNUNET_memcpy(&source_ip, &ip_pkt.src_ip, sizeof(source_ip));
- GNUNET_memcpy(&icmp_ttl, &buf[off], sizeof(struct icmp_ttl_exceeded_header));
- off += sizeof(struct icmp_ttl_exceeded_header);
- if ((ICMP_TIME_EXCEEDED != icmp_ttl.type) || (0 != icmp_ttl.code))
- {
- /* different type than what we want */
- return;
- }
- /* skip 2nd IP header */
- GNUNET_memcpy(&ip_pkt, &buf[off], sizeof(struct ip_header));
- off += sizeof(struct ip_header);
-
- switch (ip_pkt.proto)
- {
- case IPPROTO_ICMP:
- if (have !=
- (sizeof(struct ip_header) * 2 +
- sizeof(struct icmp_ttl_exceeded_header) +
- sizeof(struct icmp_echo_header)))
- {
- /* malformed */
- return;
- }
- /* grab ICMP ECHO content */
- GNUNET_memcpy(&icmp_echo, &buf[off], sizeof(struct icmp_echo_header));
- port = (uint16_t)ntohl(icmp_echo.reserved);
- break;
-
- case IPPROTO_UDP:
- if (have !=
- (sizeof(struct ip_header) * 2 +
- sizeof(struct icmp_ttl_exceeded_header) + sizeof(struct udp_header)))
- {
- /* malformed */
- return;
- }
- /* grab UDP content */
- GNUNET_memcpy(&udp_pkt, &buf[off], sizeof(struct udp_header));
- port = ntohs(udp_pkt.length);
- break;
-
- default:
- /* different type than what we want */
- return;
- }
-
- ssize = sizeof(buf);
- WSAAddressToString((LPSOCKADDR)&source_ip, sizeof(source_ip), NULL, buf,
- &ssize);
- if (port == 0)
- fprintf(stdout, "%s\n", buf);
- else
- fprintf(stdout, "%s:%u\n", buf, (unsigned int)port);
- fflush(stdout);
-}
-
-
-/**
- * Create an ICMP raw socket for reading.
- *
- * @return INVALID_SOCKET on error
- */
-static _win_socket
-make_icmp_socket()
-{
- _win_socket ret;
-
- ret = _win_socket(AF_INET, SOCK_RAW, IPPROTO_ICMP);
- if (INVALID_SOCKET == ret)
- {
- fprintf(stderr, "Error opening RAW socket: %s\n", strerror(errno));
- return INVALID_SOCKET;
- }
- return ret;
-}
-
-
-/**
- * Create an ICMP raw socket for writing.
- *
- * @return INVALID_SOCKET on error
- */
-static _win_socket
-make_raw_socket()
-{
- DWORD bOptVal = TRUE;
- int bOptLen = sizeof(bOptVal);
-
- rawsock = _win_socket(AF_INET, SOCK_RAW, IPPROTO_ICMP);
- if (INVALID_SOCKET == rawsock)
- {
- fprintf(stderr, "Error opening RAW socket: %s\n", strerror(errno));
- return INVALID_SOCKET;
- }
-
- if (0 !=
- _win_setsockopt(rawsock, SOL_SOCKET, SO_BROADCAST, (char *)&bOptVal,
- bOptLen))
- {
- fprintf(stderr, "Error setting SO_BROADCAST to ON: %s\n",
- strerror(errno));
- closesocket(rawsock);
- return INVALID_SOCKET;
- }
- if (0 !=
- _win_setsockopt(rawsock, IPPROTO_IP, IP_HDRINCL, (char *)&bOptVal, bOptLen))
- {
- fprintf(stderr, "Error setting IP_HDRINCL to ON: %s\n", strerror(errno));
- closesocket(rawsock);
- return INVALID_SOCKET;
- }
- return rawsock;
-}
-
-
-/**
- * Create a UDP socket for writing.
- *
- * @param my_ip source address (our ip address)
- * @return INVALID_SOCKET on error
- */
-static _win_socket
-make_udp_socket(const struct in_addr *my_ip)
-{
- _win_socket ret;
- struct sockaddr_in addr;
-
- ret = _win_socket(AF_INET, SOCK_DGRAM, 0);
- if (INVALID_SOCKET == ret)
- {
- fprintf(stderr, "Error opening UDP socket: %s\n", strerror(errno));
- return INVALID_SOCKET;
- }
- memset(&addr, 0, sizeof(addr));
- addr.sin_family = AF_INET;
- addr.sin_addr = *my_ip;
- addr.sin_port = htons(NAT_TRAV_PORT);
- if (0 != bind(ret, (struct sockaddr *)&addr, sizeof(addr)))
- {
- fprintf(stderr, "Error binding UDP socket to port %u: %s\n", NAT_TRAV_PORT,
- strerror(errno));
- /* likely problematic, but not certain, try to continue */
- }
- return ret;
-}
-
-
-int
-main(int argc, char *const *argv)
-{
- struct in_addr external;
- fd_set rs;
- struct timeval tv;
- WSADATA wsaData;
- unsigned int alt = 0;
-
- if ((argc > 1) && (0 != strcmp(argv[1], "-d")))
- {
- privilege_testing = TRUE;
- fprintf(stderr,
- "%s",
- "DEBUG: Running binary in privilege testing mode.");
- argv++;
- argc--;
- }
-
- if (2 != argc)
- {
- fprintf(stderr,
- "This program must be started with our (internal NAT) IP as the only argument.\n");
- return 1;
- }
- if (1 != inet_pton(AF_INET, argv[1], &external))
- {
- fprintf(stderr, "Error parsing IPv4 address: %s, error %s\n", argv[1],
- strerror(errno));
- return 1;
- }
- if (1 != inet_pton(AF_INET, DUMMY_IP, &dummy))
- {
- fprintf(stderr, "Internal error converting dummy IP to binary.\n");
- return 2;
- }
- if (WSAStartup(MAKEWORD(2, 1), &wsaData) != 0)
- {
- fprintf(stderr, "Failed to find Winsock 2.1 or better.\n");
- return 2;
- }
- if (INVALID_SOCKET == (icmpsock = make_icmp_socket()))
- {
- return 3;
- }
- if (INVALID_SOCKET == (make_raw_socket()))
- {
- closesocket(icmpsock);
- return 3;
- }
- if (INVALID_SOCKET == (udpsock = make_udp_socket(&external)))
- {
- closesocket(icmpsock);
- closesocket(rawsock);
- return 3;
- }
-
- while (!privilege_testing)
- {
- FD_ZERO(&rs);
- FD_SET(icmpsock, &rs);
- tv.tv_sec = 0;
- tv.tv_usec = ICMP_SEND_FREQUENCY_MS * 1000;
- if (-1 == select(icmpsock + 1, &rs, NULL, NULL, &tv))
- {
- if (errno == EINTR)
- continue;
- fprintf(stderr, "select failed: %s\n", strerror(errno));
- break;
- }
- if (FD_ISSET(icmpsock, &rs))
- process_icmp_response();
- if (0 == (++alt % 2))
- send_icmp_echo(&external);
- else
- send_udp();
- }
- /* select failed (internal error or OS out of resources) */
- closesocket(icmpsock);
- closesocket(rawsock);
- closesocket(udpsock);
- WSACleanup();
- if (privilege_testing)
- return 0;
- return 4;
-}
-
-
-/* end of gnunet-helper-nat-server-windows.c */
diff --git a/src/nse/Makefile.am b/src/nse/Makefile.am
index 618489780..3a79cdd97 100644
--- a/src/nse/Makefile.am
+++ b/src/nse/Makefile.am
@@ -1,10 +1,6 @@
# This Makefile.am is in the public domain
AM_CPPFLAGS = -I$(top_srcdir)/src/include
-if MINGW
- WINFLAGS = -Wl,--no-undefined -Wl,--export-all-symbols
-endif
-
if USE_COVERAGE
AM_CFLAGS = --coverage -O0
XLIB = -lgcov
diff --git a/src/nt/Makefile.am b/src/nt/Makefile.am
index 68b6a55e7..57b8d1936 100644
--- a/src/nt/Makefile.am
+++ b/src/nt/Makefile.am
@@ -1,10 +1,6 @@
# This Makefile.am is in the public domain
AM_CPPFLAGS = -I$(top_srcdir)/src/include
-if MINGW
- WINFLAGS = -Wl,--no-undefined -Wl,--export-all-symbols
-endif
-
if USE_COVERAGE
AM_CFLAGS = --coverage
endif
diff --git a/src/peerinfo-tool/Makefile.am b/src/peerinfo-tool/Makefile.am
index 8293288c8..3c133427c 100644
--- a/src/peerinfo-tool/Makefile.am
+++ b/src/peerinfo-tool/Makefile.am
@@ -1,10 +1,6 @@
# This Makefile.am is in the public domain
AM_CPPFLAGS = -I$(top_srcdir)/src/include
-if MINGW
- WINFLAGS = -Wl,--no-undefined -Wl,--export-all-symbols -lole32 -lshell32 -liconv -lstdc++ -lcomdlg32 -lgdi32
-endif
-
if USE_COVERAGE
AM_CFLAGS = --coverage -O0
XLIB = -lgcov
diff --git a/src/peerinfo/Makefile.am b/src/peerinfo/Makefile.am
index d07ed3a5b..7d1204100 100644
--- a/src/peerinfo/Makefile.am
+++ b/src/peerinfo/Makefile.am
@@ -10,10 +10,6 @@ plugindir = $(libdir)/gnunet
pkgcfg_DATA = \
peerinfo.conf
-if MINGW
- WINFLAGS = -Wl,--no-undefined -Wl,--export-all-symbols -lole32 -lshell32 -liconv -lstdc++ -lcomdlg32 -lgdi32
-endif
-
if USE_COVERAGE
AM_CFLAGS = --coverage -O0
XLIB = -lgcov
diff --git a/src/peerstore/Makefile.am b/src/peerstore/Makefile.am
index c6acdce56..003bac36d 100644
--- a/src/peerstore/Makefile.am
+++ b/src/peerstore/Makefile.am
@@ -10,10 +10,6 @@ libexecdir= $(pkglibdir)/libexec/
dist_pkgcfg_DATA = \
peerstore.conf
-if MINGW
- WINFLAGS = -Wl,--no-undefined -Wl,--export-all-symbols
-endif
-
if USE_COVERAGE
AM_CFLAGS = -fprofile-arcs -ftest-coverage
endif
diff --git a/src/pq/Makefile.am b/src/pq/Makefile.am
index d0c71703b..9270e6fe0 100644
--- a/src/pq/Makefile.am
+++ b/src/pq/Makefile.am
@@ -1,10 +1,6 @@
# This Makefile.am is in the public domain
AM_CPPFLAGS = -I$(top_srcdir)/src/include $(POSTGRESQL_CPPFLAGS)
-if MINGW
- WINFLAGS = -Wl,--no-undefined -Wl,--export-all-symbols
-endif
-
if USE_COVERAGE
AM_CFLAGS = --coverage
endif
diff --git a/src/pt/Makefile.am b/src/pt/Makefile.am
index 1d94a3429..09a68b779 100644
--- a/src/pt/Makefile.am
+++ b/src/pt/Makefile.am
@@ -1,10 +1,6 @@
# This Makefile.am is in the public domain
AM_CPPFLAGS = -I$(top_srcdir)/src/include
-if MINGW
- WINFLAGS = -Wl,--no-undefined -Wl,--export-all-symbols
-endif
-
if USE_COVERAGE
AM_CFLAGS = --coverage -O0
endif
@@ -46,13 +42,6 @@ if LINUX
test_gnunet_vpn-4_over \
test_gns_vpn
endif
-if MINGW
- VPN_TEST = \
- test_gnunet_vpn-4_to_6 \
- test_gnunet_vpn-6_to_4 \
- test_gnunet_vpn-6_over \
- test_gnunet_vpn-4_over
-endif
else
if HAVE_LIBCURL
LIB_GNURL=@LIBCURL@
@@ -65,13 +54,6 @@ if LINUX
test_gnunet_vpn-4_over \
test_gns_vpn
endif
-if MINGW
- VPN_TEST = \
- test_gnunet_vpn-4_to_6 \
- test_gnunet_vpn-6_to_4 \
- test_gnunet_vpn-6_over \
- test_gnunet_vpn-4_over
-endif
endif
endif
diff --git a/src/pt/test_gnunet_vpn.c b/src/pt/test_gnunet_vpn.c
index 60f4aad2a..c52c0c6c9 100644
--- a/src/pt/test_gnunet_vpn.c
+++ b/src/pt/test_gnunet_vpn.c
@@ -420,7 +420,6 @@ main(int argc, char *const *argv)
char *exit_binary;
int ret = 0;
-#ifndef MINGW
if (0 != access("/dev/net/tun", R_OK))
{
GNUNET_log_strerror_file(GNUNET_ERROR_TYPE_ERROR,
@@ -430,7 +429,7 @@ main(int argc, char *const *argv)
"WARNING: System unable to run test, skipping.\n");
return 77;
}
-#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!
diff --git a/src/reclaim-attribute/Makefile.am b/src/reclaim-attribute/Makefile.am
index e53f527b3..cbbcb37d6 100644
--- a/src/reclaim-attribute/Makefile.am
+++ b/src/reclaim-attribute/Makefile.am
@@ -7,10 +7,6 @@ pkgcfgdir= $(pkgdatadir)/config.d/
libexecdir= $(pkglibdir)/libexec/
-if MINGW
- WINFLAGS = -Wl,--no-undefined -Wl,--export-all-symbols
-endif
-
if USE_COVERAGE
AM_CFLAGS = --coverage -O0
XLIBS = -lgcov
diff --git a/src/reclaim/Makefile.am b/src/reclaim/Makefile.am
index 69dcc605e..851b0d71e 100644
--- a/src/reclaim/Makefile.am
+++ b/src/reclaim/Makefile.am
@@ -3,10 +3,6 @@ AM_CPPFLAGS = -I$(top_srcdir)/src/include
plugindir = $(libdir)/gnunet
-if MINGW
- WINFLAGS = -Wl,--no-undefined -Wl,--export-all-symbols
-endif
-
if USE_COVERAGE
AM_CFLAGS = --coverage -O0
XLIB = -lgcov
diff --git a/src/regex/Makefile.am b/src/regex/Makefile.am
index 2af6dcccd..ba5e0af00 100644
--- a/src/regex/Makefile.am
+++ b/src/regex/Makefile.am
@@ -1,10 +1,6 @@
# This Makefile.am is in the public domain
AM_CPPFLAGS = -I$(top_srcdir)/src/include
-if MINGW
- WINFLAGS = -Wl,--no-undefined -Wl,--export-all-symbols
-endif
-
if USE_COVERAGE
AM_CFLAGS = --coverage
endif
diff --git a/src/rest/Makefile.am b/src/rest/Makefile.am
index 1fd2816c0..41b4c6508 100644
--- a/src/rest/Makefile.am
+++ b/src/rest/Makefile.am
@@ -10,10 +10,6 @@ libexecdir= $(pkglibdir)/libexec/
pkgcfg_DATA = \
rest.conf
-if MINGW
- WINFLAGS = -Wl,--no-undefined -Wl,--export-all-symbols
-endif
-
if USE_COVERAGE
AM_CFLAGS = --coverage -O0
XLIBS = -lgcov
diff --git a/src/revocation/Makefile.am b/src/revocation/Makefile.am
index 82755b485..a6fff3524 100644
--- a/src/revocation/Makefile.am
+++ b/src/revocation/Makefile.am
@@ -3,10 +3,6 @@ AM_CPPFLAGS = -I$(top_srcdir)/src/include
plugindir = $(libdir)/gnunet
-if MINGW
- WINFLAGS = -Wl,--no-undefined -Wl,--export-all-symbols
-endif
-
if USE_COVERAGE
AM_CFLAGS = --coverage -O0
XLIB = -lgcov
diff --git a/src/rps/Makefile.am b/src/rps/Makefile.am
index ce73caa0f..0c739589f 100644
--- a/src/rps/Makefile.am
+++ b/src/rps/Makefile.am
@@ -1,10 +1,6 @@
# This Makefile.am is in the public domain
AM_CPPFLAGS = -I$(top_srcdir)/src/include
-if MINGW
- WINFLAGS = -Wl,--no-undefined -Wl,--export-all-symbols
-endif
-
if USE_COVERAGE
AM_CFLAGS = --coverage -O0
XLIB = -lgcov
diff --git a/src/scalarproduct/Makefile.am b/src/scalarproduct/Makefile.am
index 10e04284f..311cfd1af 100644
--- a/src/scalarproduct/Makefile.am
+++ b/src/scalarproduct/Makefile.am
@@ -8,10 +8,6 @@ libexecdir= $(pkglibdir)/libexec/
pkgcfg_DATA = \
scalarproduct.conf
-if MINGW
- WINFLAGS = -Wl,--no-undefined -Wl,--export-all-symbols
-endif
-
if USE_COVERAGE
AM_CFLAGS = -fprofile-arcs -ftest-coverage
endif
diff --git a/src/secretsharing/Makefile.am b/src/secretsharing/Makefile.am
index c808e8200..787cfa0c1 100644
--- a/src/secretsharing/Makefile.am
+++ b/src/secretsharing/Makefile.am
@@ -8,10 +8,6 @@ libexecdir= $(pkglibdir)/libexec/
pkgcfg_DATA = \
secretsharing.conf
-if MINGW
- WINFLAGS = -Wl,--no-undefined -Wl,--export-all-symbols
-endif
-
if USE_COVERAGE
AM_CFLAGS = -fprofile-arcs -ftest-coverage
endif
diff --git a/src/set/Makefile.am b/src/set/Makefile.am
index df17fa1ab..d6b10a1f8 100644
--- a/src/set/Makefile.am
+++ b/src/set/Makefile.am
@@ -10,10 +10,6 @@ plugindir = $(libdir)/gnunet
pkgcfg_DATA = \
set.conf
-if MINGW
- WINFLAGS = -Wl,--no-undefined -Wl,--export-all-symbols
-endif
-
if USE_COVERAGE
AM_CFLAGS = -fprofile-arcs -ftest-coverage
endif
diff --git a/src/sq/Makefile.am b/src/sq/Makefile.am
index fb9364005..893c8eac3 100644
--- a/src/sq/Makefile.am
+++ b/src/sq/Makefile.am
@@ -1,10 +1,6 @@
# This Makefile.am is in the public domain
AM_CPPFLAGS = -I$(top_srcdir)/src/include
-if MINGW
- WINFLAGS = -Wl,--no-undefined -Wl,--export-all-symbols
-endif
-
if USE_COVERAGE
AM_CFLAGS = --coverage
endif
diff --git a/src/statistics/Makefile.am b/src/statistics/Makefile.am
index 16a1ea2d0..bde35da2d 100644
--- a/src/statistics/Makefile.am
+++ b/src/statistics/Makefile.am
@@ -1,10 +1,6 @@
# This Makefile.am is in the public domain
AM_CPPFLAGS = -I$(top_srcdir)/src/include
-if MINGW
- WINFLAGS = -Wl,--no-undefined -Wl,--export-all-symbols
-endif
-
if USE_COVERAGE
AM_CFLAGS = --coverage -O0
XLIB = -lgcov
diff --git a/src/template/Makefile.am b/src/template/Makefile.am
index 5a27a6d60..4d2e58083 100644
--- a/src/template/Makefile.am
+++ b/src/template/Makefile.am
@@ -8,10 +8,6 @@ libexecdir= $(pkglibdir)/libexec/
dist_pkgcfg_DATA = \
template.conf
-if MINGW
- WINFLAGS = -Wl,--no-undefined -Wl,--export-all-symbols
-endif
-
if USE_COVERAGE
AM_CFLAGS = -fprofile-arcs -ftest-coverage
endif
diff --git a/src/testbed-logger/Makefile.am b/src/testbed-logger/Makefile.am
index a8c4c7b05..96b68df27 100644
--- a/src/testbed-logger/Makefile.am
+++ b/src/testbed-logger/Makefile.am
@@ -1,10 +1,6 @@
# This Makefile.am is in the public domain
AM_CPPFLAGS = -I$(top_srcdir)/src/include
-if MINGW
- WINFLAGS = -Wl,--no-undefined -Wl,--export-all-symbols
-endif
-
if USE_COVERAGE
AM_CFLAGS = --coverage -O0
XLIB = -lgcov
diff --git a/src/testbed/Makefile.am b/src/testbed/Makefile.am
index e858e44b4..c27a81ae9 100644
--- a/src/testbed/Makefile.am
+++ b/src/testbed/Makefile.am
@@ -1,10 +1,6 @@
# This Makefile.am is in the public domain
AM_CPPFLAGS = -I$(top_srcdir)/src/include
-if MINGW
- WINFLAGS = -Wl,--no-undefined -Wl,--export-all-symbols
-endif
-
if USE_COVERAGE
AM_CFLAGS = --coverage -O0
XLIB = -lgcov
diff --git a/src/testbed/gnunet-service-testbed_cpustatus.c b/src/testbed/gnunet-service-testbed_cpustatus.c
index b659b5dc3..f3df9a96e 100644
--- a/src/testbed/gnunet-service-testbed_cpustatus.c
+++ b/src/testbed/gnunet-service-testbed_cpustatus.c
@@ -398,114 +398,6 @@ ABORT_KSTAT:
}
#endif
-#if MINGW
- /* Win NT? */
- if (GNNtQuerySystemInformation)
- {
- static double dLastKernel;
- static double dLastIdle;
- static double dLastUser;
- double dKernel;
- double dIdle;
- double dUser;
- double dDiffKernel;
- double dDiffIdle;
- double dDiffUser;
- SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION theInfo;
-
- if (GNNtQuerySystemInformation(SystemProcessorPerformanceInformation,
- &theInfo,
- sizeof(theInfo), NULL) == NO_ERROR)
- {
- /* PORT-ME MINGW: Multi-processor? */
- dKernel = Li2Double(theInfo.KernelTime);
- dIdle = Li2Double(theInfo.IdleTime);
- dUser = Li2Double(theInfo.UserTime);
- dDiffKernel = dKernel - dLastKernel;
- dDiffIdle = dIdle - dLastIdle;
- dDiffUser = dUser - dLastUser;
-
- if (((dDiffKernel + dDiffUser) > 0) &&
- (dLastIdle + dLastKernel + dLastUser > 0))
- currentCPULoad =
- 100.0 - (dDiffIdle / (dDiffKernel + dDiffUser)) * 100.0;
- else
- currentCPULoad = -1; /* don't know (yet) */
-
- dLastKernel = dKernel;
- dLastIdle = dIdle;
- dLastUser = dUser;
-
- currentIOLoad = -1; /* FIXME-MINGW */
- return GNUNET_OK;
- }
- else
- {
- /* only warn once, if there is a problem with
- NtQuery..., we're going to hit it frequently... */
- static int once;
- if (once == 0)
- {
- once = 1;
- GNUNET_log(GNUNET_ERROR_TYPE_WARNING,
- "Cannot query the CPU usage (Windows NT).\n");
- }
- return GNUNET_SYSERR;
- }
- }
- else
- { /* Win 9x */
- HKEY hKey;
- DWORD dwDataSize, dwType, dwDummy;
-
- /* Start query */
- if (RegOpenKeyEx(HKEY_DYN_DATA,
- "PerfStats\\StartSrv",
- 0, KEY_ALL_ACCESS, &hKey) != ERROR_SUCCESS)
- {
- /* only warn once */
- static int once = 0;
- if (once == 0)
- {
- once = 1;
- GNUNET_log(GNUNET_ERROR_TYPE_WARNING,
- "Cannot query the CPU usage (Win 9x)\n");
- }
- }
-
- RegOpenKeyEx(HKEY_DYN_DATA,
- "PerfStats\\StartStat", 0, KEY_ALL_ACCESS, &hKey);
- dwDataSize = sizeof(dwDummy);
- RegQueryValueEx(hKey,
- "KERNEL\\CPUUsage",
- NULL, &dwType, (LPBYTE)&dwDummy, &dwDataSize);
- RegCloseKey(hKey);
-
- /* Get CPU usage */
- RegOpenKeyEx(HKEY_DYN_DATA,
- "PerfStats\\StatData", 0, KEY_ALL_ACCESS, &hKey);
- dwDataSize = sizeof(currentCPULoad);
- RegQueryValueEx(hKey,
- "KERNEL\\CPUUsage",
- NULL, &dwType, (LPBYTE)&currentCPULoad, &dwDataSize);
- RegCloseKey(hKey);
- currentIOLoad = -1; /* FIXME-MINGW! */
-
- /* Stop query */
- RegOpenKeyEx(HKEY_DYN_DATA,
- "PerfStats\\StopStat", 0, KEY_ALL_ACCESS, &hKey);
- RegOpenKeyEx(HKEY_DYN_DATA,
- "PerfStats\\StopSrv", 0, KEY_ALL_ACCESS, &hKey);
- dwDataSize = sizeof(dwDummy);
- RegQueryValueEx(hKey,
- "KERNEL\\CPUUsage",
- NULL, &dwType, (LPBYTE)&dwDummy, &dwDataSize);
- RegCloseKey(hKey);
-
- return GNUNET_OK;
- }
-#endif
-
/* loadaverage not defined and no platform
specific alternative defined
=> default: error
@@ -695,12 +587,6 @@ GST_stats_init(const struct GNUNET_CONFIGURATION_Handle *cfg)
char *fn;
size_t len;
-#if MINGW
- GNUNET_log(GNUNET_ERROR_TYPE_WARNING,
- "Load statistics logging now available for windows\n");
- return; /* No logging on windows for now :( */
-#endif
-
if (GNUNET_OK !=
GNUNET_CONFIGURATION_get_value_filename(cfg, "testbed",
"STATS_DIR", &stats_dir))
@@ -747,9 +633,6 @@ GST_stats_init(const struct GNUNET_CONFIGURATION_Handle *cfg)
void
GST_stats_destroy()
{
-#if MINGW
- return;
-#endif
if (NULL == bw)
return;
#ifdef LINUX
diff --git a/src/testbed/test_testbed_api_testbed_run.c b/src/testbed/test_testbed_api_testbed_run.c
index 39bc9bfe7..a3bd415dd 100644
--- a/src/testbed/test_testbed_api_testbed_run.c
+++ b/src/testbed/test_testbed_api_testbed_run.c
@@ -215,18 +215,7 @@ main(int argc, char **argv)
}
testname++;
testname = GNUNET_strdup(testname);
-#ifdef MINGW
- {
- char *period;
-
- /* check and remove .exe extension */
- period = strrchr(testname, (int)'.');
- if (NULL != period)
- *period = '\0';
- else
- GNUNET_break(0); /* Windows with no .exe? */
- }
-#endif
+
if (0 == strcmp("waitforever", testname))
wait_forever = GNUNET_YES;
if ((GNUNET_YES != wait_forever) && (0 != strcmp("run", testname)))
diff --git a/src/testing/Makefile.am b/src/testing/Makefile.am
index 39e5f1574..9c6357455 100644
--- a/src/testing/Makefile.am
+++ b/src/testing/Makefile.am
@@ -1,10 +1,6 @@
# This Makefile.am is in the public domain
AM_CPPFLAGS = -I$(top_srcdir)/src/include
-if MINGW
- WINFLAGS = -Wl,--no-undefined -Wl,--export-all-symbols
-endif
-
if USE_COVERAGE
AM_CFLAGS = --coverage -O0
XLIB = -lgcov
diff --git a/src/transport/Makefile.am b/src/transport/Makefile.am
index a9b0d19d6..0f5b2e8be 100644
--- a/src/transport/Makefile.am
+++ b/src/transport/Makefile.am
@@ -114,18 +114,12 @@ if HAVE_LIBBLUETOOTH
BT_QUOTA_TEST = test_quota_compliance_bluetooth \
test_quota_compliance_bluetooth_asymmetric
endif
-else
-if MINGW
- BT_BIN = gnunet-helper-transport-bluetooth
- BT_PLUGIN_LA = libgnunet_plugin_transport_bluetooth.la
-endif
endif
# end of HAVE_EXPERIMENTAL
endif
-if !MINGW
UNIX_PLUGIN_LA = libgnunet_plugin_transport_unix.la
UNIX_PLUGIN_TEST = test_transport_api_unix
UNIX_TEST = test_plugin_unix
@@ -136,7 +130,7 @@ UNIX_QUOTA_TEST = test_quota_compliance_unix \
if LINUX
UNIX_API_ABSTRACT_TEST = test_transport_api_unix_abstract
endif
-endif
+
noinst_PROGRAMS = \
gnunet-transport-profiler \
@@ -319,13 +313,9 @@ gnunet_transport_wlan_receiver_LDADD = \
gnunet_helper_transport_bluetooth_SOURCES = \
gnunet-helper-transport-bluetooth.c
-if MINGW
- gnunet_helper_transport_bluetooth_LDADD = \
- $(top_builddir)/src/util/libgnunetutil.la
- gnunet_helper_transport_bluetooth_LDFLAGS = -lws2_32
-else
- gnunet_helper_transport_bluetooth_LDFLAGS = -lbluetooth
-endif
+
+gnunet_helper_transport_bluetooth_LDFLAGS = -lbluetooth
+
gnunet_transport_profiler_SOURCES = \
gnunet-transport-profiler.c
diff --git a/src/transport/gnunet-helper-transport-bluetooth.c b/src/transport/gnunet-helper-transport-bluetooth.c
index 2ac705996..4696f48f8 100644
--- a/src/transport/gnunet-helper-transport-bluetooth.c
+++ b/src/transport/gnunet-helper-transport-bluetooth.c
@@ -21,30 +21,23 @@
*/
#include "gnunet_config.h"
-#ifdef MINGW
- #include "platform.h"
- #include "gnunet_util_lib.h"
- #include <bthdef.h>
- #include <ws2bth.h>
-#else
- #define SOCKTYPE int
- #include <bluetooth/bluetooth.h>
- #include <bluetooth/hci.h>
- #include <bluetooth/hci_lib.h>
- #include <bluetooth/rfcomm.h>
- #include <bluetooth/sdp.h>
- #include <bluetooth/sdp_lib.h>
- #include <errno.h>
- #include <linux/if.h>
- #include <stdio.h>
- #include <stdlib.h>
- #include <sys/ioctl.h>
- #include <sys/param.h>
- #include <sys/socket.h>
- #include <sys/stat.h>
- #include <sys/types.h>
- #include <unistd.h>
-#endif
+#define SOCKTYPE int
+#include <bluetooth/bluetooth.h>
+#include <bluetooth/hci.h>
+#include <bluetooth/hci_lib.h>
+#include <bluetooth/rfcomm.h>
+#include <bluetooth/sdp.h>
+#include <bluetooth/sdp_lib.h>
+#include <errno.h>
+#include <linux/if.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <sys/ioctl.h>
+#include <sys/param.h>
+#include <sys/socket.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+#include <unistd.h>
#include "plugin_transport_wlan.h"
#include "gnunet_protocols.h"
@@ -67,34 +60,6 @@
*/
#define MAX_LOOPS 5
-#ifdef MINGW
-/* Maximum size of the interface's name */
- #define IFNAMSIZ 16
-
- #ifndef NS_BTH
- #define NS_BTH 16
- #endif
-/**
- * A copy of the MAC Address.
- */
-struct GNUNET_TRANSPORT_WLAN_MacAddress_Copy {
- UINT8 mac[MAC_ADDR_SIZE];
-};
-
-/**
- * The UUID used for the SDP service.
- * {31191E56-FA7E-4517-870E-71B86BBCC52F}
- */
- #define GNUNET_BLUETOOTH_SDP_UUID \
- { \
- 0x31, 0x19, 0x1E, 0x56, \
- 0xFA, 0x7E, \
- 0x45, 0x17, \
- 0x87, 0x0E, \
- 0x71, 0xB8, 0x6B, 0xBC, 0xC5, 0x2F \
- }
-#endif
-
/**
* In bluez library, the maximum name length of a device is 8
*/
@@ -110,17 +75,6 @@ struct HardwareInfos {
*/
char iface[IFNAMSIZ];
- #ifdef MINGW
- /**
- * socket handle
- */
- struct GNUNET_NETWORK_Handle *handle;
-
- /**
- * MAC address of our own bluetooth interface.
- */
- struct GNUNET_TRANSPORT_WLAN_MacAddress_Copy pl_mac;
- #else
/**
* file descriptor for the rfcomm socket
*/
@@ -135,7 +89,6 @@ struct HardwareInfos {
* SDP session
*/
sdp_session_t *session;
- #endif
};
/**
@@ -606,61 +559,6 @@ check_crc_buf_osdep(const unsigned char *buf, size_t len)
/* ************** end of clone ***************** */
-
-#ifdef MINGW
-/**
- * Function used to get the code of last error and to print the type of error.
- */
-static void
-print_last_error()
-{
- LPVOID lpMsgBuf = NULL;
-
- if (FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
- NULL, GetLastError(), 0, (LPTSTR)&lpMsgBuf, 0, NULL))
- fprintf(stderr, "%s\n", (char *)lpMsgBuf);
- else
- fprintf(stderr, "Failed to format the message for the last error! Error number : %d\n", GetLastError());
-}
-
-/**
- * Function used to initialize the Windows Sockets
- */
-static void
-initialize_windows_sockets()
-{
- WSADATA wsaData;
- WORD wVersionRequested = MAKEWORD(2, 0);
-
- if (WSAStartup(wVersionRequested, &wsaData) != NO_ERROR)
- {
- fprintf(stderr, "Error initializing window sockets!\n");
- print_last_error();
- ExitProcess(2);
- }
-}
-
-/**
- * Function used to convert the GUID.
- * @param bytes the GUID represented as a char array
- * @param uuid pointer to the GUID
- */
-static void
-convert_guid(char *bytes, GUID * uuid)
-{
- int i;
-
- uuid->Data1 = ((bytes[0] << 24) & 0xff000000) | ((bytes[1] << 16) & 0x00ff0000) | ((bytes[2] << 8) & 0x0000ff00) | (bytes[3] & 0x000000ff);
- uuid->Data2 = ((bytes[4] << 8) & 0xff00) | (bytes[5] & 0x00ff);
- uuid->Data3 = ((bytes[6] << 8) & 0xff00) | (bytes[7] & 0x00ff);
-
- for (i = 0; i < 8; i++)
- {
- uuid->Data4[i] = bytes[i + 8];
- }
-}
-#endif
-
#ifdef LINUX
/**
* Function for assigning a port number
@@ -688,79 +586,6 @@ bind_socket(int socket, struct sockaddr_rc *addr)
}
#endif
-#ifdef MINGW
-/**
- * Function used for creating the service record and registering it.
- *
- * @param dev pointer to the device struct
- * @return 0 on success
- */
-static int
-register_service(struct HardwareInfos *dev)
-{
- /* advertise the service */
- CSADDR_INFO addr_info;
- WSAQUERYSET wqs;
- GUID guid;
- unsigned char uuid[] = GNUNET_BLUETOOTH_SDP_UUID;
- SOCKADDR_BTH addr;
- int addr_len = sizeof(SOCKADDR_BTH);
- int fd;
-
- /* get the port on which we are listening on */
- memset(&addr, 0, sizeof(SOCKADDR_BTH));
- fd = GNUNET_NETWORK_get_fd(dev->handle);
- if (fd <= 0)
- {
- fprintf(stderr, "Failed to get the file descriptor\n");
- return -1;
- }
- if (SOCKET_ERROR == getsockname(fd, (SOCKADDR*)&addr, &addr_len))
- {
- fprintf(stderr, "Failed to get the port on which we are listening on: \n");
- print_last_error();
- return -1;
- }
-
- /* save the device address */
- GNUNET_memcpy(&dev->pl_mac, &addr.btAddr, sizeof(BTH_ADDR));
-
- /* set the address information */
- memset(&addr_info, 0, sizeof(CSADDR_INFO));
- addr_info.iProtocol = BTHPROTO_RFCOMM;
- addr_info.iSocketType = SOCK_STREAM;
- addr_info.LocalAddr.lpSockaddr = (LPSOCKADDR)&addr;
- addr_info.LocalAddr.iSockaddrLength = sizeof(addr);
- addr_info.RemoteAddr.lpSockaddr = (LPSOCKADDR)&addr;
- addr_info.RemoteAddr.iSockaddrLength = sizeof(addr);
-
- convert_guid((char *)uuid, &guid);
-
- /* register the service */
- memset(&wqs, 0, sizeof(WSAQUERYSET));
- wqs.dwSize = sizeof(WSAQUERYSET);
- wqs.dwNameSpace = NS_BTH;
- wqs.lpszServiceInstanceName = "GNUnet Bluetooth Service";
- wqs.lpszComment = "This is the service used by the GNUnnet plugin transport";
- wqs.lpServiceClassId = &guid;
- wqs.dwNumberOfCsAddrs = 1;
- wqs.lpcsaBuffer = &addr_info;
- wqs.lpBlob = 0;
-
- if (SOCKET_ERROR == WSASetService(&wqs, RNRSERVICE_REGISTER, 0))
- {
- fprintf(stderr, "Failed to register the SDP service: ");
- print_last_error();
- return -1;
- }
- else
- {
- fprintf(stderr, "The SDP service was registered\n");
- }
-
- return 0;
-}
-#else
/**
* Function used for creating the service record and registering it.
*
@@ -849,96 +674,7 @@ register_service(struct HardwareInfos *dev, int rc_channel)
return 0;
}
-#endif
-#ifdef MINGW
-/**
- * Function for searching and browsing for a service. This will return the
- * port number on which the service is running.
- *
- * @param dest target address
- * @return channel
- */
-static int
-get_channel(const char *dest)
-{
- HANDLE h;
- WSAQUERYSET *wqs;
- DWORD wqs_len = sizeof(WSAQUERYSET);
- int done = 0;
- int channel = -1;
- GUID guid;
- unsigned char uuid[] = GNUNET_BLUETOOTH_SDP_UUID;
-
- convert_guid((char *)uuid, &guid);
-
- wqs = (WSAQUERYSET*)malloc(wqs_len);
- ZeroMemory(wqs, wqs_len);
-
- wqs->dwSize = sizeof(WSAQUERYSET);
- wqs->lpServiceClassId = &guid;
- wqs->dwNameSpace = NS_BTH;
- wqs->dwNumberOfCsAddrs = 0;
- wqs->lpszContext = (LPSTR)dest;
-
- if (SOCKET_ERROR == WSALookupServiceBegin(wqs, LUP_FLUSHCACHE | LUP_RETURN_ALL, &h))
- {
- if (GetLastError() == WSASERVICE_NOT_FOUND)
- {
- fprintf(stderr, "WARNING! The device with address %s wasn't found. Skipping the message!", dest);
- return -1;
- }
- else
- {
- fprintf(stderr, "Failed to find the port number: ");
- print_last_error();
- ExitProcess(2);
- return -1;
- }
- }
-
- /* search the sdp service */
- while (!done)
- {
- if (SOCKET_ERROR == WSALookupServiceNext(h, LUP_FLUSHCACHE | LUP_RETURN_ALL, &wqs_len, wqs))
- {
- int error = WSAGetLastError();
-
- switch (error)
- {
- case WSAEFAULT:
- free(wqs);
- wqs = (WSAQUERYSET*)malloc(wqs_len);
- break;
-
- case WSANO_DATA:
- fprintf(stderr, "Failed! The address was valid but there was no data record of requested type\n");
- done = 1;
- break;
-
- case WSA_E_NO_MORE:
- done = 1;
- break;
-
- default:
- fprintf(stderr, "Failed to look over the services: ");
- print_last_error();
- WSALookupServiceEnd(h);
- ExitProcess(2);
- }
- }
- else
- {
- channel = ((SOCKADDR_BTH*)wqs->lpcsaBuffer->RemoteAddr.lpSockaddr)->port;
- }
- }
-
- free(wqs);
- WSALookupServiceEnd(h);
-
- return channel;
-}
-#else
/**
* Function used for searching and browsing for a service. This will return the
* port number on which the service is running.
@@ -1011,7 +747,6 @@ get_channel(struct HardwareInfos *dev, bdaddr_t dest)
return channel;
}
-#endif
/**
* Read from the socket and put the result into the buffer for transmission to 'stdout'.
@@ -1030,22 +765,14 @@ read_from_the_socket(void *sock,
{
unsigned char tmpbuf[buf_size];
ssize_t count;
-
- #ifdef MINGW
- count = GNUNET_NETWORK_socket_recv((struct GNUNET_NETWORK_Handle *)sock, tmpbuf, buf_size);
- #else
count = read(*((int *)sock), tmpbuf, buf_size);
- #endif
if (0 > count)
{
if (EAGAIN == errno)
return 0;
- #if MINGW
- print_last_error();
- #else
+
fprintf(stderr, "Failed to read from the HCI socket: %s\n", strerror(errno));
- #endif
return -1;
}
@@ -1088,43 +815,6 @@ read_from_the_socket(void *sock,
static int
open_device(struct HardwareInfos *dev)
{
- #ifdef MINGW
- SOCKADDR_BTH addr;
-
- /* bind the RFCOMM socket to the interface */
- addr.addressFamily = AF_BTH;
- addr.btAddr = 0;
- addr.port = BT_PORT_ANY;
-
- if (GNUNET_OK !=
- GNUNET_NETWORK_socket_bind(dev->handle, (const SOCKADDR*)&addr, sizeof(SOCKADDR_BTH)))
- {
- fprintf(stderr, "Failed to bind the socket: ");
- if (GetLastError() == WSAENETDOWN)
- {
- fprintf(stderr, "Please make sure that your Bluetooth device is ON!\n");
- ExitProcess(2);
- }
- print_last_error();
- return -1;
- }
-
- /* start listening on the socket */
- if (GNUNET_NETWORK_socket_listen(dev->handle, 4) != GNUNET_OK)
- {
- fprintf(stderr, "Failed to listen on the socket: ");
- print_last_error();
- return -1;
- }
-
- /* register the sdp service */
- if (register_service(dev) != 0)
- {
- fprintf(stderr, "Failed to register a service: ");
- print_last_error();
- return 1;
- }
- #else
int i, dev_id = -1, fd_hci;
struct {
struct hci_dev_list_req list;
@@ -1279,7 +969,6 @@ open_device(struct HardwareInfos *dev)
dev->iface, strerror(errno));
return 1;
}
- #endif
return 0;
}
@@ -1299,12 +988,7 @@ mac_set(struct GNUNET_TRANSPORT_WLAN_Ieee80211Frame *taIeeeHeader,
{
taIeeeHeader->frame_control = htons(IEEE80211_FC0_TYPE_DATA);
taIeeeHeader->addr3 = mac_bssid_gnunet;
-
- #ifdef MINGW
- GNUNET_memcpy(&taIeeeHeader->addr2, &dev->pl_mac, sizeof(struct GNUNET_TRANSPORT_WLAN_MacAddress));
- #else
taIeeeHeader->addr2 = dev->pl_mac;
- #endif
}
#ifdef LINUX
diff --git a/src/transport/plugin_transport_udp.c b/src/transport/plugin_transport_udp.c
index 755809194..c056bb79c 100644
--- a/src/transport/plugin_transport_udp.c
+++ b/src/transport/plugin_transport_udp.c
@@ -2929,20 +2929,7 @@ udp_select_read(struct Plugin *plugin, struct GNUNET_NETWORK_Handle *rsock)
(struct sockaddr *)&addr,
&fromlen);
sa = (const struct sockaddr *)&addr;
-#if MINGW
- /* On SOCK_DGRAM UDP sockets recvfrom might fail with a
- * WSAECONNRESET error to indicate that previous sendto() (yes, sendto!)
- * on this socket has failed.
- * Quote from MSDN:
- * WSAECONNRESET - The virtual circuit was reset by the remote side
- * executing a hard or abortive close. The application should close
- * the socket; it is no longer usable. On a UDP-datagram socket this
- * error indicates a previous send operation resulted in an ICMP Port
- * Unreachable message.
- */
- if ((-1 == size) && (ECONNRESET == errno))
- return;
-#endif
+
if (-1 == size)
{
LOG(GNUNET_ERROR_TYPE_DEBUG,
diff --git a/src/transport/plugin_transport_wlan.h b/src/transport/plugin_transport_wlan.h
index cdc3e34ff..bf1a90dba 100644
--- a/src/transport/plugin_transport_wlan.h
+++ b/src/transport/plugin_transport_wlan.h
@@ -32,12 +32,7 @@
/**
* Number fo bytes in a mac address.
*/
-#ifdef MINGW
- #define MAC_ADDR_SIZE 8
-typedef uint8_t u_int8_t;
-#else
- #define MAC_ADDR_SIZE 6
-#endif
+#define MAC_ADDR_SIZE 6
/**
* Value for "Management" in the 'frame_control' field of the
diff --git a/src/transport/tcp_service_legacy.c b/src/transport/tcp_service_legacy.c
index 8f3f43718..129511fec 100644
--- a/src/transport/tcp_service_legacy.c
+++ b/src/transport/tcp_service_legacy.c
@@ -849,95 +849,6 @@ LEGACY_SERVICE_get_server_addresses(
}
-#ifdef MINGW
-/**
- * Read listen sockets from the parent process (ARM).
- *
- * @param sctx service context to initialize
- * @return #GNUNET_YES if ok, #GNUNET_NO if not ok (must bind yourself),
- * and #GNUNET_SYSERR on error.
- */
-static int
-receive_sockets_from_parent(struct LEGACY_SERVICE_Context *sctx)
-{
- const char *env_buf;
- int fail;
- uint64_t count;
- uint64_t i;
- HANDLE lsocks_pipe;
-
- env_buf = getenv("GNUNET_OS_READ_LSOCKS");
- if ((NULL == env_buf) || (strlen(env_buf) <= 0))
- return GNUNET_NO;
- /* Using W32 API directly here, because this pipe will
- * never be used outside of this function, and it's just too much of a bother
- * to create a GNUnet API that boxes a HANDLE (the way it is done with socks)
- */
- lsocks_pipe = (HANDLE)strtoul(env_buf, NULL, 10);
- if ((0 == lsocks_pipe) || (INVALID_HANDLE_VALUE == lsocks_pipe))
- return GNUNET_NO;
- fail = 1;
- do
- {
- int ret;
- int fail2;
- DWORD rd;
-
- ret = ReadFile(lsocks_pipe, &count, sizeof(count), &rd, NULL);
- if ((0 == ret) || (sizeof(count) != rd) || (0 == count))
- break;
- sctx->lsocks =
- GNUNET_malloc(sizeof(struct GNUNET_NETWORK_Handle *) * (count + 1));
-
- fail2 = 1;
- for (i = 0; i < count; i++)
- {
- WSAPROTOCOL_INFOA pi;
- uint64_t size;
- socket s;
-
- ret = ReadFile(lsocks_pipe, &size, sizeof(size), &rd, NULL);
- if ((0 == ret) || (sizeof(size) != rd) || (sizeof(pi) != size))
- break;
- ret = ReadFile(lsocks_pipe, &pi, sizeof(pi), &rd, NULL);
- if ((0 == ret) || (sizeof(pi) != rd))
- break;
- s = WSASocketA(pi.iAddressFamily,
- pi.iSocketType,
- pi.iProtocol,
- &pi,
- 0,
- WSA_FLAG_OVERLAPPED);
- sctx->lsocks[i] = GNUNET_NETWORK_socket_box_native(s);
- if (NULL == sctx->lsocks[i])
- break;
- else if (i == count - 1)
- fail2 = 0;
- }
- if (fail2)
- break;
- sctx->lsocks[count] = NULL;
- fail = 0;
- }
- while (fail);
-
- CloseHandle(lsocks_pipe);
-
- if (fail)
- {
- LOG(GNUNET_ERROR_TYPE_ERROR,
- _("Could not access a pre-bound socket, will try to bind myself\n"));
- for (i = 0; (i < count) && (NULL != sctx->lsocks[i]); i++)
- GNUNET_break(0 == GNUNET_NETWORK_socket_close(sctx->lsocks[i]));
- GNUNET_free_non_null(sctx->lsocks);
- sctx->lsocks = NULL;
- return GNUNET_NO;
- }
- return GNUNET_YES;
-}
-#endif
-
-
/**
* Setup addr, addrlen, idle_timeout
* based on configuration!
@@ -961,12 +872,9 @@ setup_service(struct LEGACY_SERVICE_Context *sctx)
{
struct GNUNET_TIME_Relative idleout;
int tolerant;
-
-#ifndef MINGW
const char *nfds;
unsigned int cnt;
int flags;
-#endif
if (GNUNET_CONFIGURATION_have_value(sctx->cfg,
sctx->service_name,
@@ -1007,7 +915,6 @@ setup_service(struct LEGACY_SERVICE_Context *sctx)
else
tolerant = GNUNET_NO;
-#ifndef MINGW
errno = 0;
if ((NULL != (nfds = getenv("LISTEN_FDS"))) &&
(1 == sscanf(nfds, "%u", &cnt)) && (cnt > 0) && (cnt < FD_SETSIZE) &&
@@ -1036,13 +943,6 @@ setup_service(struct LEGACY_SERVICE_Context *sctx)
}
unsetenv("LISTEN_FDS");
}
-#else
- if (getenv("GNUNET_OS_READ_LSOCKS") != NULL)
- {
- receive_sockets_from_parent(sctx);
- putenv("GNUNET_OS_READ_LSOCKS=");
- }
-#endif
if ((NULL == sctx->lsocks) &&
(GNUNET_SYSERR == LEGACY_SERVICE_get_server_addresses(sctx->service_name,
@@ -1257,7 +1157,6 @@ service_task(void *cls)
static int
detach_terminal(struct LEGACY_SERVICE_Context *sctx)
{
-#ifndef MINGW
pid_t pid;
int nullfd;
int filedes[2];
@@ -1324,11 +1223,7 @@ detach_terminal(struct LEGACY_SERVICE_Context *sctx)
if (-1 == pid)
LOG_STRERROR(GNUNET_ERROR_TYPE_ERROR, "setsid");
sctx->ready_confirm_fd = filedes[1];
-#else
- /* FIXME: we probably need to do something else
- * elsewhere in order to fork the process itself... */
- FreeConsole();
-#endif
+
return GNUNET_OK;
}
@@ -1346,7 +1241,7 @@ set_user_id(struct LEGACY_SERVICE_Context *sctx)
if (NULL == (user = get_user_name(sctx)))
return GNUNET_OK; /* keep */
-#ifndef MINGW
+
struct passwd *pws;
errno = 0;
@@ -1377,7 +1272,7 @@ set_user_id(struct LEGACY_SERVICE_Context *sctx)
return GNUNET_SYSERR;
}
}
-#endif
+
GNUNET_free(user);
return GNUNET_OK;
}
diff --git a/src/util/Makefile.am b/src/util/Makefile.am
index 647f09224..c240053ff 100644
--- a/src/util/Makefile.am
+++ b/src/util/Makefile.am
@@ -13,27 +13,7 @@ dist_pkgcfg_DATA = \
pkgcfg_DATA = \
resolver.conf
-if MINGW
-noinst_LTLIBRARIES = \
- libgnunetutilwin.la
-libgnunetutilwin_la_SOURCES = \
- win.c \
- winproc.c
-libgnunetutilwin_la_LDFLAGS = \
- -no-undefined -Wl,--export-all-symbols
-libgnunetutilwin_la_LIBADD = \
- -lshell32 -liconv -lstdc++ \
- -lcomdlg32 -lgdi32 -liphlpapi
-WINLIB = libgnunetutilwin.la
-W32CAT = w32cat
-W32CONSOLEHELPER = gnunet-helper-w32-console
-endif
-
-if !MINGW
- TEST_CLIENT_UNIX_NC = test_client_unix.nc
-else
- TEST_CLIENT_UNIX_NC =
-endif
+TEST_CLIENT_UNIX_NC = test_client_unix.nc
if USE_COVERAGE
AM_CFLAGS = --coverage -O0
@@ -45,14 +25,6 @@ if ENABLE_BENCHMARK
PTHREAD = -lpthread
endif
-w32cat_SOURCES = w32cat.c
-
-gnunet_helper_w32_console_SOURCES = \
- gnunet-helper-w32-console.c \
- gnunet-helper-w32-console.h
-gnunet_helper_w32_console_LDADD = \
- libgnunetutil.la
-
gnunet_config_diff_SOURCES = \
gnunet-config-diff.c
gnunet_config_diff_LDADD = \
@@ -202,8 +174,7 @@ lib_LTLIBRARIES = libgnunetutil.la
libexec_PROGRAMS = \
gnunet-service-resolver \
- gnunet-timeout \
- $(W32CONSOLEHELPER)
+ gnunet-timeout
bin_PROGRAMS = \
gnunet-resolver \
@@ -217,7 +188,6 @@ endif
noinst_PROGRAMS = \
gnunet-config-diff \
- $(W32CAT) \
test_common_logging_dummy
@@ -228,14 +198,8 @@ endif
endif
-
-if !MINGW
gnunet_timeout_SOURCES = \
gnunet-timeout.c
-else
-gnunet_timeout_SOURCES = \
- gnunet-timeout-w32.c
-endif
gnunet_service_resolver_SOURCES = \
gnunet-service-resolver.c
@@ -393,8 +357,7 @@ test_os_start_process_SOURCES = \
test_os_start_process_LDADD = \
libgnunetutil.la
test_os_start_process_DEPENDENCIES = \
- libgnunetutil.la \
- $(WINCAT)
+ libgnunetutil.la
test_client_nc_SOURCES = \
test_client.c
diff --git a/src/util/disk.c b/src/util/disk.c
index 01d5efbe2..8b474542b 100644
--- a/src/util/disk.c
+++ b/src/util/disk.c
@@ -96,7 +96,6 @@ struct GetFileSizeData {
};
-#ifndef MINGW
/**
* Translate GNUnet-internal permission bitmap to UNIX file
* access permission bitmap.
@@ -131,7 +130,6 @@ translate_unix_perms(enum GNUNET_DISK_AccessPermissions perm)
return mode;
}
-#endif
/**
@@ -191,11 +189,7 @@ getSizeRec(void *cls, const char *fn)
int
GNUNET_DISK_handle_invalid(const struct GNUNET_DISK_FileHandle *h)
{
-#ifdef MINGW
- return ((!h) || (h->h == INVALID_HANDLE_VALUE)) ? GNUNET_YES : GNUNET_NO;
-#else
return ((!h) || (h->fd == -1)) ? GNUNET_YES : GNUNET_NO;
-#endif
}
/**
@@ -236,26 +230,9 @@ GNUNET_DISK_file_seek(const struct GNUNET_DISK_FileHandle *h,
return GNUNET_SYSERR;
}
-#ifdef MINGW
- LARGE_INTEGER li;
- LARGE_INTEGER new_pos;
- BOOL b;
-
- static DWORD t[] = { FILE_BEGIN, FILE_CURRENT, FILE_END };
- li.QuadPart = offset;
-
- b = SetFilePointerEx(h->h, li, &new_pos, t[whence]);
- if (b == 0)
- {
- SetErrnoFromWinError(GetLastError());
- return GNUNET_SYSERR;
- }
- return (off_t)new_pos.QuadPart;
-#else
static int t[] = { SEEK_SET, SEEK_CUR, SEEK_END };
return lseek(h->fd, offset, t[whence]);
-#endif
}
@@ -1296,7 +1273,7 @@ GNUNET_DISK_file_open(const char *fn,
expfn = GNUNET_STRINGS_filename_expand(fn);
if (NULL == expfn)
return NULL;
-#ifndef MINGW
+
mode = 0;
if (GNUNET_DISK_OPEN_READWRITE == (flags & GNUNET_DISK_OPEN_READWRITE))
oflags = O_RDWR; /* note: O_RDWR is NOT always O_RDONLY | O_WRONLY */
@@ -1342,69 +1319,6 @@ GNUNET_DISK_file_open(const char *fn,
GNUNET_free(expfn);
return NULL;
}
-#else
- access = 0;
- disp = OPEN_ALWAYS;
-
- if (GNUNET_DISK_OPEN_READWRITE == (flags & GNUNET_DISK_OPEN_READWRITE))
- access = FILE_READ_DATA | FILE_WRITE_DATA;
- else if (flags & GNUNET_DISK_OPEN_READ)
- access = FILE_READ_DATA;
- else if (flags & GNUNET_DISK_OPEN_WRITE)
- access = FILE_WRITE_DATA;
-
- if (flags & GNUNET_DISK_OPEN_FAILIFEXISTS)
- {
- disp = CREATE_NEW;
- }
- else if (flags & GNUNET_DISK_OPEN_CREATE)
- {
- (void)GNUNET_DISK_directory_create_for_file(expfn);
- if (flags & GNUNET_DISK_OPEN_TRUNCATE)
- disp = CREATE_ALWAYS;
- else
- disp = OPEN_ALWAYS;
- }
- else if (flags & GNUNET_DISK_OPEN_TRUNCATE)
- {
- disp = TRUNCATE_EXISTING;
- }
- else
- {
- disp = OPEN_EXISTING;
- }
-
- if (ERROR_SUCCESS == plibc_conv_to_win_pathwconv(expfn, wexpfn))
- h = CreateFileW(wexpfn,
- access,
- FILE_SHARE_DELETE | FILE_SHARE_READ | FILE_SHARE_WRITE,
- NULL,
- disp,
- FILE_ATTRIBUTE_NORMAL,
- NULL);
- else
- h = INVALID_HANDLE_VALUE;
- if (h == INVALID_HANDLE_VALUE)
- {
- int err;
- SetErrnoFromWinError(GetLastError());
- err = errno;
- LOG_STRERROR_FILE(GNUNET_ERROR_TYPE_INFO, "open", expfn);
- GNUNET_free(expfn);
- errno = err;
- return NULL;
- }
-
- if (flags & GNUNET_DISK_OPEN_APPEND)
- if (SetFilePointer(h, 0, 0, FILE_END) == INVALID_SET_FILE_POINTER)
- {
- SetErrnoFromWinError(GetLastError());
- LOG_STRERROR_FILE(GNUNET_ERROR_TYPE_WARNING, "SetFilePointer", expfn);
- CloseHandle(h);
- GNUNET_free(expfn);
- return NULL;
- }
-#endif
ret = GNUNET_new(struct GNUNET_DISK_FileHandle);
diff --git a/src/util/dnsstub.c b/src/util/dnsstub.c
index ab7a08318..fef4b5f5d 100644
--- a/src/util/dnsstub.c
+++ b/src/util/dnsstub.c
@@ -291,16 +291,12 @@ do_dns_read(struct GNUNET_DNSSTUB_RequestSocket *rs,
ssize_t r;
int len;
-#ifndef MINGW
if (0 != ioctl(GNUNET_NETWORK_get_fd(dnsout), FIONREAD, &len))
{
/* conservative choice: */
len = UINT16_MAX;
}
-#else
- /* port the code above? */
- len = UINT16_MAX;
-#endif
+
GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Receiving %d byte DNS reply\n", len);
{
unsigned char buf[len] GNUNET_ALIGN;
diff --git a/src/util/gnunet-timeout-w32.c b/src/util/gnunet-timeout-w32.c
deleted file mode 100644
index 3e579714c..000000000
--- a/src/util/gnunet-timeout-w32.c
+++ /dev/null
@@ -1,193 +0,0 @@
-/*
- This file is part of GNUnet
- Copyright (C) 2010 GNUnet e.V.
-
- GNUnet is free software: you can redistribute it and/or modify it
- under the terms of the GNU Affero General Public License as published
- by the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
-
- GNUnet is distributed in the hope that it will be useful, but
- WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- Affero General Public License for more details.
-
- You should have received a copy of the GNU Affero General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>.
-
- SPDX-License-Identifier: AGPL3.0-or-later
- */
-
-/**
- * @file src/util/gnunet-timeout-w32.c
- * @brief small tool starting a child process, waiting that it terminates or killing it after a given timeout period
- * @author LRN
- */
-
-#include <windows.h>
-#include <sys/types.h>
-#include <stdio.h>
-
-int
-main(int argc, char *argv[])
-{
- int i;
- DWORD wait_result;
- wchar_t *commandline;
- wchar_t **wargv;
- wchar_t *arg;
- unsigned int cmdlen;
- STARTUPINFOW start;
- PROCESS_INFORMATION proc;
-
- wchar_t wpath[MAX_PATH + 1];
-
- wchar_t *pathbuf;
- DWORD pathbuf_len, alloc_len;
- wchar_t *ptr;
- wchar_t *non_const_filename;
- wchar_t *wcmd;
- int wargc;
- int timeout = 0;
- ssize_t wrote;
-
- HANDLE job;
-
- if (argc < 3)
- {
- printf
- ("arg 1: timeout in sec., arg 2: executable, arg<n> arguments\n");
- exit(1);
- }
-
- timeout = atoi(argv[1]);
-
- if (timeout == 0)
- timeout = 600;
-
- commandline = GetCommandLineW();
- if (commandline == NULL)
- {
- printf("Failed to get commandline: %lu\n", GetLastError());
- exit(2);
- }
-
- wargv = CommandLineToArgvW(commandline, &wargc);
- if (wargv == NULL || wargc <= 1)
- {
- printf("Failed to get parse commandline: %lu\n", GetLastError());
- exit(3);
- }
-
- job = CreateJobObject(NULL, NULL);
- if (job == NULL)
- {
- printf("Failed to create a job: %lu\n", GetLastError());
- exit(4);
- }
-
- pathbuf_len = GetEnvironmentVariableW(L"PATH", (wchar_t *)&pathbuf, 0);
-
- alloc_len = pathbuf_len + 1;
-
- pathbuf = malloc(alloc_len * sizeof(wchar_t));
-
- ptr = pathbuf;
-
- alloc_len = GetEnvironmentVariableW(L"PATH", ptr, pathbuf_len);
-
- cmdlen = wcslen(wargv[2]);
- if (cmdlen < 5 || wcscmp(&wargv[2][cmdlen - 4], L".exe") != 0)
- {
- non_const_filename = malloc(sizeof(wchar_t) * (cmdlen + 5));
- swprintf(non_const_filename, cmdlen + 5, L"%S.exe", wargv[2]);
- }
- else
- {
- non_const_filename = wcsdup(wargv[2]);
- }
-
- /* Check that this is the full path. If it isn't, search. */
- if (non_const_filename[1] == L':')
- swprintf(wpath, sizeof(wpath) / sizeof(wchar_t), L"%S", non_const_filename);
- else if (!SearchPathW
- (pathbuf, non_const_filename, NULL, sizeof(wpath) / sizeof(wchar_t),
- wpath, NULL))
- {
- printf("Failed to get find executable: %lu\n", GetLastError());
- exit(5);
- }
- free(pathbuf);
- free(non_const_filename);
-
- cmdlen = wcslen(wpath) + 4;
- i = 3;
- while (NULL != (arg = wargv[i++]))
- cmdlen += wcslen(arg) + 4;
-
- wcmd = malloc(sizeof(wchar_t) * (cmdlen + 1));
- wrote = 0;
- i = 2;
- while (NULL != (arg = wargv[i++]))
- {
- /* This is to escape trailing slash */
- wchar_t arg_lastchar = arg[wcslen(arg) - 1];
- if (wrote == 0)
- {
- wrote += swprintf(&wcmd[wrote], cmdlen + 1 - wrote, L"\"%S%S\" ", wpath,
- arg_lastchar == L'\\' ? L"\\" : L"");
- }
- else
- {
- if (wcschr(arg, L' ') != NULL)
- wrote += swprintf(&wcmd[wrote], cmdlen + 1 - wrote, L"\"%S%S\"%S", arg,
- arg_lastchar == L'\\' ? L"\\" : L"", i == wargc ? L"" : L" ");
- else
- wrote += swprintf(&wcmd[wrote], cmdlen + 1 - wrote, L"%S%S%S", arg,
- arg_lastchar == L'\\' ? L"\\" : L"", i == wargc ? L"" : L" ");
- }
- }
-
- LocalFree(wargv);
-
- memset(&start, 0, sizeof(start));
- start.cb = sizeof(start);
-
- if (!CreateProcessW(wpath, wcmd, NULL, NULL, TRUE, CREATE_SUSPENDED,
- NULL, NULL, &start, &proc))
- {
- wprintf(L"Failed to get spawn process `%S' with arguments `%S': %lu\n", wpath, wcmd, GetLastError());
- exit(6);
- }
-
- AssignProcessToJobObject(job, proc.hProcess);
-
- ResumeThread(proc.hThread);
- CloseHandle(proc.hThread);
-
- free(wcmd);
-
- wait_result = WaitForSingleObject(proc.hProcess, timeout * 1000);
- if (wait_result == WAIT_OBJECT_0)
- {
- DWORD status;
- wait_result = GetExitCodeProcess(proc.hProcess, &status);
- CloseHandle(proc.hProcess);
- if (wait_result != 0)
- {
- printf("Test process exited with result %lu\n", status);
- TerminateJobObject(job, status);
- exit(status);
- }
- printf("Test process exited (failed to obtain exit status)\n");
- TerminateJobObject(job, 0);
- exit(0);
- }
- printf("Child processes were killed after timeout of %u seconds\n",
- timeout);
- TerminateJobObject(job, 1);
- CloseHandle(proc.hProcess);
- exit(1);
-}
-
-/* end of timeout_watchdog_w32.c */
diff --git a/src/util/network.c b/src/util/network.c
index ec76424eb..6f8a8ff5a 100644
--- a/src/util/network.c
+++ b/src/util/network.c
@@ -759,10 +759,6 @@ GNUNET_NETWORK_socket_recvfrom(const struct GNUNET_NETWORK_Handle *desc,
flags,
src_addr,
addrlen);
-#ifdef MINGW
- if (SOCKET_ERROR == ret)
- SetErrnoFromWinsockError(WSAGetLastError());
-#endif
return ret;
}
@@ -792,10 +788,6 @@ GNUNET_NETWORK_socket_recv(const struct GNUNET_NETWORK_Handle *desc,
buffer,
length,
flags);
-#ifdef MINGW
- if (SOCKET_ERROR == ret)
- SetErrnoFromWinsockError(WSAGetLastError());
-#endif
return ret;
}
@@ -827,10 +819,6 @@ GNUNET_NETWORK_socket_send(const struct GNUNET_NETWORK_Handle *desc,
buffer,
length,
flags);
-#ifdef MINGW
- if (SOCKET_ERROR == ret)
- SetErrnoFromWinsockError(WSAGetLastError());
-#endif
return ret;
}
@@ -865,10 +853,6 @@ GNUNET_NETWORK_socket_sendto(const struct GNUNET_NETWORK_Handle *desc,
flags |= MSG_NOSIGNAL;
#endif
ret = sendto(desc->fd, message, length, flags, dest_addr, dest_len);
-#ifdef MINGW
- if (SOCKET_ERROR == ret)
- SetErrnoFromWinsockError(WSAGetLastError());
-#endif
return ret;
}
@@ -897,10 +881,7 @@ GNUNET_NETWORK_socket_setsockopt(struct GNUNET_NETWORK_Handle *fd,
option_name,
option_value,
option_len);
-#ifdef MINGW
- if (SOCKET_ERROR == ret)
- SetErrnoFromWinsockError(WSAGetLastError());
-#endif
+
return ret == 0 ? GNUNET_OK : GNUNET_SYSERR;
}
@@ -950,10 +931,7 @@ GNUNET_NETWORK_socket_shutdown(struct GNUNET_NETWORK_Handle *desc,
int ret;
ret = shutdown(desc->fd, how);
-#ifdef MINGW
- if (0 != ret)
- SetErrnoFromWinsockError(WSAGetLastError());
-#endif
+
return (0 == ret) ? GNUNET_OK : GNUNET_SYSERR;
}
@@ -1054,7 +1032,6 @@ void
GNUNET_NETWORK_fdset_add(struct GNUNET_NETWORK_FDSet *dst,
const struct GNUNET_NETWORK_FDSet *src)
{
-#ifndef MINGW
int nfds;
for (nfds = src->nsds; nfds >= 0; nfds--)
@@ -1062,31 +1039,6 @@ GNUNET_NETWORK_fdset_add(struct GNUNET_NETWORK_FDSet *dst,
FD_SET(nfds, &dst->sds);
dst->nsds = GNUNET_MAX(dst->nsds,
src->nsds);
-#else
- /* This is MinGW32-specific implementation that relies on the code that
- * winsock2.h defines for FD_SET. Namely, it relies on FD_SET checking
- * that fd being added is not already in the set.
- * Also relies on us knowing what's inside fd_set (fd_count and fd_array).
- *
- * NOTE: I don't understand why the UNIX-logic wouldn't work
- * for the first part here as well. -CG
- */
- unsigned int i;
-
- for (i = 0; i < src->sds.fd_count; i++)
- FD_SET(src->sds.fd_array[i],
- &dst->sds);
- dst->nsds = GNUNET_MAX(src->nsds,
- dst->nsds);
-
- /* also copy over `struct GNUNET_DISK_FileHandle` array */
- if (dst->handles_pos + src->handles_pos > dst->handles_size)
- GNUNET_array_grow(dst->handles,
- dst->handles_size,
- ((dst->handles_pos + src->handles_pos) << 1));
- for (i = 0; i < src->handles_pos; i++)
- dst->handles[dst->handles_pos++] = src->handles[i];
-#endif
}
@@ -1103,16 +1055,6 @@ GNUNET_NETWORK_fdset_copy(struct GNUNET_NETWORK_FDSet *to,
FD_COPY(&from->sds,
&to->sds);
to->nsds = from->nsds;
-#ifdef MINGW
- if (from->handles_pos > to->handles_size)
- GNUNET_array_grow(to->handles,
- to->handles_size,
- from->handles_pos * 2);
- GNUNET_memcpy(to->handles,
- from->handles,
- from->handles_pos * sizeof(struct GNUNET_NETWORK_Handle *));
- to->handles_pos = from->handles_pos;
-#endif
}
@@ -1217,13 +1159,6 @@ void
GNUNET_NETWORK_fdset_handle_set(struct GNUNET_NETWORK_FDSet *fds,
const struct GNUNET_DISK_FileHandle *h)
{
-#ifdef MINGW
- if (fds->handles_pos == fds->handles_size)
- GNUNET_array_grow(fds->handles,
- fds->handles_size,
- fds->handles_size * 2 + 2);
- fds->handles[fds->handles_pos++] = h;
-#else
int fd;
GNUNET_assert(GNUNET_OK ==
@@ -1234,7 +1169,6 @@ GNUNET_NETWORK_fdset_handle_set(struct GNUNET_NETWORK_FDSet *fds,
&fds->sds);
fds->nsds = GNUNET_MAX(fd + 1,
fds->nsds);
-#endif
}
@@ -1247,22 +1181,7 @@ void
GNUNET_NETWORK_fdset_handle_set_first(struct GNUNET_NETWORK_FDSet *fds,
const struct GNUNET_DISK_FileHandle *h)
{
-#ifdef MINGW
- if (fds->handles_pos == fds->handles_size)
- GNUNET_array_grow(fds->handles,
- fds->handles_size,
- fds->handles_size * 2 + 2);
- fds->handles[fds->handles_pos] = h;
- if (fds->handles[0] != h)
- {
- const struct GNUNET_DISK_FileHandle *bak = fds->handles[0];
- fds->handles[0] = h;
- fds->handles[fds->handles_pos] = bak;
- }
- fds->handles_pos++;
-#else
GNUNET_NETWORK_fdset_handle_set(fds, h);
-#endif
}
@@ -1277,42 +1196,11 @@ int
GNUNET_NETWORK_fdset_handle_isset(const struct GNUNET_NETWORK_FDSet *fds,
const struct GNUNET_DISK_FileHandle *h)
{
-#ifdef MINGW
- unsigned int i;
-
- for (i = 0; i < fds->handles_pos; i++)
- if (fds->handles[i] == h)
- return GNUNET_YES;
- return GNUNET_NO;
-#else
return FD_ISSET(h->fd,
&fds->sds);
-#endif
}
-#ifdef MINGW
-/**
- * Numerically compare pointers to sort them.
- * Used to test for overlap in the arrays.
- *
- * @param p1 a pointer
- * @param p2 a pointer
- * @return -1, 0 or 1, if the p1 < p2, p1==p2 or p1 > p2.
- */
-static int
-ptr_cmp(const void *p1,
- const void *p2)
-{
- if (p1 == p2)
- return 0;
- if ((intptr_t)p1 < (intptr_t)p2)
- return -1;
- return 1;
-}
-#endif
-
-
/**
* Checks if two fd sets overlap
*
@@ -1324,7 +1212,6 @@ int
GNUNET_NETWORK_fdset_overlap(const struct GNUNET_NETWORK_FDSet *fds1,
const struct GNUNET_NETWORK_FDSet *fds2)
{
-#ifndef MINGW
int nfds;
nfds = GNUNET_MIN(fds1->nsds,
@@ -1339,53 +1226,6 @@ GNUNET_NETWORK_fdset_overlap(const struct GNUNET_NETWORK_FDSet *fds1,
return GNUNET_YES;
}
return GNUNET_NO;
-#else
- unsigned int i;
- unsigned int j;
-
- /* This code is somewhat hacky, we are not supposed to know what's
- * inside of fd_set; also the O(n^2) is really bad... */
- for (i = 0; i < fds1->sds.fd_count; i++)
- for (j = 0; j < fds2->sds.fd_count; j++)
- if (fds1->sds.fd_array[i] == fds2->sds.fd_array[j])
- return GNUNET_YES;
-
- /* take a short cut if possible */
- if ((0 == fds1->handles_pos) ||
- (0 == fds2->handles_pos))
- return GNUNET_NO;
-
- /* Sort file handles array to avoid quadratic complexity when
- checking for overlap */
- qsort(fds1->handles,
- fds1->handles_pos,
- sizeof(void *),
- &ptr_cmp);
- qsort(fds2->handles,
- fds2->handles_pos,
- sizeof(void *),
- &ptr_cmp);
- i = 0;
- j = 0;
- while ((i < fds1->handles_pos) &&
- (j < fds2->handles_pos))
- {
- switch (ptr_cmp(fds1->handles[i],
- fds2->handles[j]))
- {
- case -1:
- i++;
- break;
-
- case 0:
- return GNUNET_YES;
-
- case 1:
- j++;
- }
- }
- return GNUNET_NO;
-#endif
}
@@ -1413,192 +1253,10 @@ GNUNET_NETWORK_fdset_create()
void
GNUNET_NETWORK_fdset_destroy(struct GNUNET_NETWORK_FDSet *fds)
{
-#ifdef MINGW
- GNUNET_array_grow(fds->handles,
- fds->handles_size,
- 0);
-#endif
GNUNET_free(fds);
}
-#if MINGW
-/**
- * FIXME.
- */
-struct _select_params {
- /**
- * Read set.
- */
- fd_set *r;
-
- /**
- * Write set.
- */
- fd_set *w;
-
- /**
- * Except set.
- */
- fd_set *e;
-
- /**
- * Timeout for select().
- */
- struct timeval *tv;
-
- /**
- * FIXME.
- */
- HANDLE wakeup;
-
- /**
- * FIXME.
- */
- HANDLE standby;
-
- /**
- * FIXME.
- */
- _win_socket wakeup_socket;
-
- /**
- * Set to return value from select.
- */
- int status;
-};
-
-
-/**
- * FIXME.
- */
-static DWORD WINAPI
-_selector(LPVOID p)
-{
- struct _select_params *sp = p;
-
- while (1)
- {
- WaitForSingleObject(sp->standby,
- INFINITE);
- ResetEvent(sp->standby);
- sp->status = select(1,
- sp->r,
- sp->w,
- sp->e,
- sp->tv);
- if (FD_ISSET(sp->wakeup_socket,
- sp->r))
- {
- FD_CLR(sp->wakeup_socket,
- sp->r);
- sp->status -= 1;
- }
- SetEvent(sp->wakeup);
- }
- return 0;
-}
-
-
-static HANDLE hEventPipeWrite;
-
-static HANDLE hEventReadReady;
-
-static struct _select_params sp;
-
-static HANDLE select_thread;
-
-static HANDLE select_finished_event;
-
-static HANDLE select_standby_event;
-
-static _win_socket select_wakeup_socket = -1;
-
-static _win_socket select_send_socket = -1;
-
-static struct timeval select_timeout;
-
-
-/**
- * On W32, we actually use a thread to help with the
- * event loop due to W32-API limitations. This function
- * initializes that thread.
- */
-static void
-initialize_select_thread()
-{
- _win_socket select_listening_socket = -1;
- struct sockaddr_in s_in;
- int alen;
- int res;
- unsigned long p;
-
- select_standby_event = CreateEvent(NULL, TRUE, FALSE, NULL);
- select_finished_event = CreateEvent(NULL, TRUE, FALSE, NULL);
-
- select_wakeup_socket = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
-
- select_listening_socket = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
-
- p = 1;
- res = ioctlsocket(select_wakeup_socket, FIONBIO, &p);
- LOG(GNUNET_ERROR_TYPE_DEBUG,
- "Select thread initialization: ioctlsocket() returns %d\n",
- res);
-
- alen = sizeof(s_in);
- s_in.sin_family = AF_INET;
- s_in.sin_port = 0;
- s_in.sin_addr.S_un.S_un_b.s_b1 = 127;
- s_in.sin_addr.S_un.S_un_b.s_b2 = 0;
- s_in.sin_addr.S_un.S_un_b.s_b3 = 0;
- s_in.sin_addr.S_un.S_un_b.s_b4 = 1;
- res = bind(select_listening_socket,
- (const struct sockaddr *)&s_in,
- sizeof(s_in));
- LOG(GNUNET_ERROR_TYPE_DEBUG,
- "Select thread initialization: bind() returns %d\n",
- res);
-
- res = getsockname(select_listening_socket,
- (struct sockaddr *)&s_in,
- &alen);
- LOG(GNUNET_ERROR_TYPE_DEBUG,
- "Select thread initialization: getsockname() returns %d\n",
- res);
-
- res = listen(select_listening_socket,
- SOMAXCONN);
- LOG(GNUNET_ERROR_TYPE_DEBUG,
- "Select thread initialization: listen() returns %d\n",
- res);
- res = connect(select_wakeup_socket,
- (const struct sockaddr *)&s_in,
- sizeof(s_in));
- LOG(GNUNET_ERROR_TYPE_DEBUG,
- "Select thread initialization: connect() returns %d\n",
- res);
-
- select_send_socket = accept(select_listening_socket,
- (struct sockaddr *)&s_in,
- &alen);
-
- closesocket(select_listening_socket);
-
- sp.wakeup = select_finished_event;
- sp.standby = select_standby_event;
- sp.wakeup_socket = select_wakeup_socket;
-
- select_thread = CreateThread(NULL,
- 0,
- _selector,
- &sp,
- 0, NULL);
-}
-
-
-#endif
-
/**
* Test if the given @a port is available.
*
@@ -1657,7 +1315,6 @@ GNUNET_NETWORK_test_port_free(int ipproto,
}
-#ifndef MINGW
/**
* Check if sockets or pipes meet certain conditions
*
@@ -1714,523 +1371,4 @@ GNUNET_NETWORK_socket_select(struct GNUNET_NETWORK_FDSet *rfds,
GNUNET_TIME_UNIT_FOREVER_REL.rel_value_us) ? NULL : &tv);
}
-
-#else
-/* MINGW */
-
-
-/**
- * Non-blocking test if a pipe is ready for reading.
- *
- * @param fh pipe handle
- * @return #GNUNET_YES if the pipe is ready for reading
- */
-static int
-pipe_read_ready(const struct GNUNET_DISK_FileHandle *fh)
-{
- DWORD error;
- BOOL bret;
- DWORD waitstatus = 0;
-
- SetLastError(0);
- bret = PeekNamedPipe(fh->h, NULL, 0, NULL, &waitstatus, NULL);
- error = GetLastError();
- if (0 == bret)
- {
- /* TODO: either add more errors to this condition, or eliminate it
- * entirely (failed to peek -> pipe is in serious trouble, should
- * be selected as readable).
- */
- if ((error != ERROR_BROKEN_PIPE) &&
- (error != ERROR_INVALID_HANDLE))
- return GNUNET_NO;
- }
- else if (waitstatus <= 0)
- return GNUNET_NO;
- return GNUNET_YES;
-}
-
-
-/**
- * Non-blocking test if a pipe is having an IO exception.
- *
- * @param fh pipe handle
- * @return #GNUNET_YES if the pipe is having an IO exception.
- */
-static int
-pipe_except_ready(const struct GNUNET_DISK_FileHandle *fh)
-{
- DWORD dwBytes;
-
- if (PeekNamedPipe(fh->h, NULL, 0, NULL, &dwBytes, NULL))
- return GNUNET_NO;
- return GNUNET_YES;
-}
-
-
-/**
- * Iterate over handles in fds, destructively rewrite the
- * handles array contents of fds so that it starts with the
- * handles that are ready, and update handles_pos accordingly.
- *
- * @param fds set of handles (usually pipes) to be checked for readiness
- * @param except GNUNET_NO if fds should be checked for readiness to read,
- * GNUNET_YES if fds should be checked for exceptions
- * (there is no way to check for write-readiness - pipes are always write-ready)
- * @param set_for_sure a HANDLE that is known to be set already,
- * because WaitForMultipleObjects() returned its index.
- * @return number of ready handles
- */
-static int
-check_handles_status(struct GNUNET_NETWORK_FDSet *fds,
- int except,
- HANDLE set_for_sure)
-{
- const struct GNUNET_DISK_FileHandle *fh;
- unsigned int roff;
- unsigned int woff;
-
- for (woff = 0, roff = 0; roff < fds->handles_pos; roff++)
- {
- fh = fds->handles[roff];
- if (fh == set_for_sure)
- {
- fds->handles[woff++] = fh;
- }
- else if (fh->type == GNUNET_DISK_HANLDE_TYPE_PIPE)
- {
- if ((except && pipe_except_ready(fh)) ||
- (!except && pipe_read_ready(fh)))
- fds->handles[woff++] = fh;
- }
- else if (fh->type == GNUNET_DISK_HANLDE_TYPE_FILE)
- {
- if (!except)
- fds->handles[woff++] = fh;
- }
- else
- {
- if (WAIT_OBJECT_0 == WaitForSingleObject(fh->h, 0))
- fds->handles[woff++] = fh;
- }
- }
- fds->handles_pos = woff;
- return woff;
-}
-
-
-/**
- * Check if sockets or pipes meet certain conditions, version for W32.
- *
- * @param rfds set of sockets or pipes to be checked for readability
- * @param wfds set of sockets or pipes to be checked for writability
- * @param efds set of sockets or pipes to be checked for exceptions
- * @param timeout relative value when to return
- * @return number of selected sockets or pipes, #GNUNET_SYSERR on error
- */
-int
-GNUNET_NETWORK_socket_select(struct GNUNET_NETWORK_FDSet *rfds,
- struct GNUNET_NETWORK_FDSet *wfds,
- struct GNUNET_NETWORK_FDSet *efds,
- const struct GNUNET_TIME_Relative timeout)
-{
- const struct GNUNET_DISK_FileHandle *fh;
- int nfds;
- int handles;
- unsigned int i;
- int retcode;
- uint64_t mcs_total;
- DWORD ms_rounded;
- int nhandles = 0;
- int read_pipes_off;
- HANDLE handle_array[FD_SETSIZE + 2];
- int returncode;
- int returnedpos = 0;
- int selectret;
- fd_set aread;
- fd_set awrite;
- fd_set aexcept;
-
- nfds = 0;
- handles = 0;
- if (NULL != rfds)
- {
- nfds = GNUNET_MAX(nfds, rfds->nsds);
- handles += rfds->handles_pos;
- }
- if (NULL != wfds)
- {
- nfds = GNUNET_MAX(nfds, wfds->nsds);
- handles += wfds->handles_pos;
- }
- if (NULL != efds)
- {
- nfds = GNUNET_MAX(nfds, efds->nsds);
- handles += efds->handles_pos;
- }
-
- if ((0 == nfds) &&
- (GNUNET_TIME_UNIT_FOREVER_REL.rel_value_us == timeout.rel_value_us) &&
- (0 == handles))
- {
- GNUNET_break(0);
- LOG(GNUNET_ERROR_TYPE_ERROR,
- _("Fatal internal logic error, process hangs in `%s' (abort with CTRL-C)!\n"),
- "select");
- }
-#define SAFE_FD_ISSET(fd, set) (set != NULL && FD_ISSET(fd, set))
- /* calculate how long we need to wait in microseconds */
- if (timeout.rel_value_us == GNUNET_TIME_UNIT_FOREVER_REL.rel_value_us)
- {
- mcs_total = INFINITE;
- ms_rounded = INFINITE;
- }
- else
- {
- mcs_total = timeout.rel_value_us / GNUNET_TIME_UNIT_MICROSECONDS.rel_value_us;
- ms_rounded = (DWORD)(mcs_total / GNUNET_TIME_UNIT_MILLISECONDS.rel_value_us);
- if (mcs_total > 0 && ms_rounded == 0)
- ms_rounded = 1;
- }
- /* select() may be used as a portable way to sleep */
- if (!(rfds || wfds || efds))
- {
- Sleep(ms_rounded);
- return 0;
- }
-
- if (NULL == select_thread)
- initialize_select_thread();
-
- FD_ZERO(&aread);
- FD_ZERO(&awrite);
- FD_ZERO(&aexcept);
- if (rfds)
- FD_COPY(&rfds->sds, &aread);
- if (wfds)
- FD_COPY(&wfds->sds, &awrite);
- if (efds)
- FD_COPY(&efds->sds, &aexcept);
-
- /* Start by doing a fast check on sockets and pipes (without
- waiting). It is cheap, and is sufficient most of the time. By
- profiling we detected that to be true in 90% of the cases.
- */
-
- /* Do the select now */
- select_timeout.tv_sec = 0;
- select_timeout.tv_usec = 0;
-
- /* Copy all the writes to the except, so we can detect connect() errors */
- for (i = 0; i < awrite.fd_count; i++)
- FD_SET(awrite.fd_array[i],
- &aexcept);
- if ((aread.fd_count > 0) ||
- (awrite.fd_count > 0) ||
- (aexcept.fd_count > 0))
- selectret = select(1,
- (NULL != rfds) ? &aread : NULL,
- (NULL != wfds) ? &awrite : NULL,
- &aexcept,
- &select_timeout);
- else
- selectret = 0;
- if (-1 == selectret)
- {
- /* Throw an error early on, while we still have the context. */
- LOG(GNUNET_ERROR_TYPE_ERROR,
- "W32 select(%d, %d, %d) failed: %lu\n",
- rfds ? aread.fd_count : 0,
- wfds ? awrite.fd_count : 0,
- aexcept.fd_count,
- GetLastError());
- GNUNET_assert(0);
- }
-
- /* Check aexcept, if something is in there and we copied that
- FD before to detect connect() errors, add it back to the
- write set to report errors. */
- if (NULL != wfds)
- for (i = 0; i < aexcept.fd_count; i++)
- if (FD_ISSET(aexcept.fd_array[i],
- &wfds->sds))
- FD_SET(aexcept.fd_array[i],
- &awrite);
-
-
- /* If our select returned something or is a 0-timed request, then
- also check the pipes and get out of here! */
- /* Sadly, it means code duplication :( */
- if ((selectret > 0) || (0 == mcs_total))
- {
- retcode = 0;
-
- /* Read Pipes */
- if (rfds && (rfds->handles_pos > 0))
- retcode += check_handles_status(rfds, GNUNET_NO, NULL);
-
- /* wfds handles remain untouched, on W32
- we pretend our pipes are "always" write-ready */
-
- /* except pipes */
- if (efds && (efds->handles_pos > 0))
- retcode += check_handles_status(efds, GNUNET_YES, NULL);
-
- if (rfds)
- {
- GNUNET_NETWORK_fdset_zero(rfds);
- if (selectret != -1)
- GNUNET_NETWORK_fdset_copy_native(rfds, &aread, selectret);
- }
- if (wfds)
- {
- GNUNET_NETWORK_fdset_zero(wfds);
- if (selectret != -1)
- GNUNET_NETWORK_fdset_copy_native(wfds, &awrite, selectret);
- }
- if (efds)
- {
- GNUNET_NETWORK_fdset_zero(efds);
- if (selectret != -1)
- GNUNET_NETWORK_fdset_copy_native(efds, &aexcept, selectret);
- }
- if (-1 == selectret)
- return -1;
- /* Add our select() FDs to the total return value */
- retcode += selectret;
- return retcode;
- }
-
- /* If we got this far, use slower implementation that is able to do a waiting select
- on both sockets and pipes simultaneously */
-
- /* Events for pipes */
- if (!hEventReadReady)
- hEventReadReady = CreateEvent(NULL, TRUE, TRUE, NULL);
- if (!hEventPipeWrite)
- hEventPipeWrite = CreateEvent(NULL, TRUE, TRUE, NULL);
- retcode = 0;
-
- FD_ZERO(&aread);
- FD_ZERO(&awrite);
- FD_ZERO(&aexcept);
- if (rfds)
- FD_COPY(&rfds->sds, &aread);
- if (wfds)
- FD_COPY(&wfds->sds, &awrite);
- if (efds)
- FD_COPY(&efds->sds, &aexcept);
- /* We will first Add the PIPES to the events */
- /* Track how far in `handle_array` the read pipes go,
- so we may by-pass them quickly if none of them
- are selected. */
- read_pipes_off = 0;
- if (rfds && (rfds->handles_pos > 0))
- {
- for (i = 0; i < rfds->handles_pos; i++)
- {
- fh = rfds->handles[i];
- if (fh->type == GNUNET_DISK_HANLDE_TYPE_EVENT)
- {
- handle_array[nhandles++] = fh->h;
- continue;
- }
- if (fh->type != GNUNET_DISK_HANLDE_TYPE_PIPE)
- continue;
- /* Read zero bytes to check the status of the pipe */
- if (!ReadFile(fh->h, NULL, 0, NULL, fh->oOverlapRead))
- {
- DWORD error_code = GetLastError();
-
- if (error_code == ERROR_IO_PENDING)
- {
- /* add as unready */
- handle_array[nhandles++] = fh->oOverlapRead->hEvent;
- read_pipes_off++;
- }
- else
- {
- /* add as ready */
- handle_array[nhandles++] = hEventReadReady;
- read_pipes_off++;
- }
- }
- else
- {
- /* error also counts as ready */
- handle_array[nhandles++] = hEventReadReady;
- read_pipes_off++;
- }
- }
- }
-
- if (wfds && (wfds->handles_pos > 0))
- {
- LOG(GNUNET_ERROR_TYPE_DEBUG,
- "Adding the write ready event to the array as %d\n",
- nhandles);
- handle_array[nhandles++] = hEventPipeWrite;
- }
-
- sp.status = 0;
- if (nfds > 0)
- {
- LOG(GNUNET_ERROR_TYPE_DEBUG,
- "Adding the socket event to the array as %d\n",
- nhandles);
- handle_array[nhandles++] = select_finished_event;
- if (timeout.rel_value_us == GNUNET_TIME_UNIT_FOREVER_REL.rel_value_us)
- {
- sp.tv = NULL;
- }
- else
- {
- select_timeout.tv_sec = timeout.rel_value_us / GNUNET_TIME_UNIT_SECONDS.rel_value_us;
- select_timeout.tv_usec = (timeout.rel_value_us -
- (select_timeout.tv_sec *
- GNUNET_TIME_UNIT_SECONDS.rel_value_us));
- sp.tv = &select_timeout;
- }
- FD_SET(select_wakeup_socket, &aread);
- do
- {
- i = recv(select_wakeup_socket,
- (char *)&returnedpos,
- 1,
- 0);
- }
- while (i == 1);
- sp.r = &aread;
- sp.w = &awrite;
- sp.e = &aexcept;
- /* Failed connections cause sockets to be set in errorfds on W32,
- * but on POSIX it should set them in writefds.
- * First copy all awrite sockets to aexcept, later we'll
- * check aexcept and set its contents in awrite as well
- * Sockets are also set in errorfds when OOB data is available,
- * but we don't use OOB data.
- */
- for (i = 0; i < awrite.fd_count; i++)
- FD_SET(awrite.fd_array[i],
- &aexcept);
- ResetEvent(select_finished_event);
- SetEvent(select_standby_event);
- }
-
- /* NULL-terminate array */
- handle_array[nhandles] = NULL;
- LOG(GNUNET_ERROR_TYPE_DEBUG,
- "nfds: %d, handles: %d, will wait: %llu mcs\n",
- nfds,
- nhandles,
- mcs_total);
- if (nhandles)
- {
- returncode
- = WaitForMultipleObjects(nhandles,
- handle_array,
- FALSE,
- ms_rounded);
- LOG(GNUNET_ERROR_TYPE_DEBUG,
- "WaitForMultipleObjects Returned: %d\n",
- returncode);
- }
- else if (nfds > 0)
- {
- GNUNET_break(0); /* This branch shouldn't actually be executed...*/
- i = (int)WaitForSingleObject(select_finished_event,
- INFINITE);
- returncode = WAIT_TIMEOUT;
- }
- else
- {
- /* Shouldn't come this far. If it does - investigate. */
- GNUNET_assert(0);
- }
-
- if (nfds > 0)
- {
- /* Don't wake up select-thread when delay is 0, it should return immediately
- * and wake up by itself.
- */
- if (0 != mcs_total)
- i = send(select_send_socket,
- (const char *)&returnedpos,
- 1,
- 0);
- i = (int)WaitForSingleObject(select_finished_event,
- INFINITE);
- LOG(GNUNET_ERROR_TYPE_DEBUG,
- "Finished waiting for the select thread: %d %d\n",
- i,
- sp.status);
- if (0 != mcs_total)
- {
- do
- {
- i = recv(select_wakeup_socket,
- (char *)&returnedpos,
- 1, 0);
- }
- while (1 == i);
- }
- /* Check aexcept, add its contents to awrite */
- for (i = 0; i < aexcept.fd_count; i++)
- FD_SET(aexcept.fd_array[i], &awrite);
- }
-
- returnedpos = returncode - WAIT_OBJECT_0;
- LOG(GNUNET_ERROR_TYPE_DEBUG,
- "return pos is: %d\n",
- returnedpos);
-
- if (rfds)
- {
- /* We queued a zero-long read on each pipe to check
- * its state, now we must cancel these read operations.
- * This must be done while rfds->handles_pos is still
- * intact and matches the number of read handles that we
- * got from the caller.
- */
- for (i = 0; i < rfds->handles_pos; i++)
- {
- fh = rfds->handles[i];
- if (GNUNET_DISK_HANLDE_TYPE_PIPE == fh->type)
- CancelIo(fh->h);
- }
-
- /* We may have some pipes ready for reading. */
- if (returnedpos < read_pipes_off)
- retcode += check_handles_status(rfds, GNUNET_NO, handle_array[returnedpos]);
- else
- rfds->handles_pos = 0;
-
- if (-1 != sp.status)
- GNUNET_NETWORK_fdset_copy_native(rfds, &aread, retcode);
- }
- if (wfds)
- {
- retcode += wfds->handles_pos;
- /* wfds handles remain untouched */
- if (-1 != sp.status)
- GNUNET_NETWORK_fdset_copy_native(wfds, &awrite, retcode);
- }
- if (efds)
- {
- retcode += check_handles_status(rfds,
- GNUNET_YES,
- returnedpos < nhandles ? handle_array[returnedpos] : NULL);
- if (-1 != sp.status)
- GNUNET_NETWORK_fdset_copy_native(efds, &aexcept, retcode);
- }
-
- if (sp.status > 0)
- retcode += sp.status;
-
- return retcode;
-}
-
-/* MINGW */
-#endif
-
/* end of network.c */
diff --git a/src/util/os_installation.c b/src/util/os_installation.c
index 104a98da6..c8590c8fb 100644
--- a/src/util/os_installation.c
+++ b/src/util/os_installation.c
@@ -764,26 +764,6 @@ GNUNET_OS_check_helper_binary(const char *binary,
char *p;
char *pf;
-#ifdef MINGW
- char *binaryexe;
-
- GNUNET_asprintf(&binaryexe, "%s.exe", binary);
- if ((GNUNET_YES ==
- GNUNET_STRINGS_path_is_absolute(binaryexe, GNUNET_NO, NULL, NULL)) ||
- (0 == strncmp(binary, "./", 2)))
- p = GNUNET_strdup(binaryexe);
- else
- {
- p = get_path_from_PATH(binaryexe);
- if (NULL != p)
- {
- GNUNET_asprintf(&pf, "%s/%s", p, binaryexe);
- GNUNET_free(p);
- p = pf;
- }
- }
- GNUNET_free(binaryexe);
-#else
if ((GNUNET_YES ==
GNUNET_STRINGS_path_is_absolute(binary, GNUNET_NO, NULL, NULL)) ||
(0 == strncmp(binary, "./", 2)))
@@ -800,7 +780,7 @@ GNUNET_OS_check_helper_binary(const char *binary,
p = pf;
}
}
-#endif
+
if (NULL == p)
{
LOG(GNUNET_ERROR_TYPE_INFO,
@@ -814,14 +794,14 @@ GNUNET_OS_check_helper_binary(const char *binary,
GNUNET_free(p);
return GNUNET_SYSERR;
}
-#ifndef MINGW
+
if (0 == getuid())
{
/* as we run as root, we don't insist on SUID */
GNUNET_free(p);
return GNUNET_YES;
}
-#endif
+
if (0 != stat(p, &statbuf))
{
LOG_STRERROR_FILE(GNUNET_ERROR_TYPE_WARNING, "stat", p);
@@ -830,7 +810,6 @@ GNUNET_OS_check_helper_binary(const char *binary,
}
if (check_suid)
{
-#ifndef MINGW
(void)params;
if ((0 != (statbuf.st_mode & S_ISUID)) && (0 == statbuf.st_uid))
{
@@ -841,57 +820,6 @@ GNUNET_OS_check_helper_binary(const char *binary,
_("Binary `%s' exists, but is not SUID\n"),
p);
/* binary exists, but not SUID */
-#else
- STARTUPINFO start;
- char parameters[512];
- PROCESS_INFORMATION proc;
- DWORD exit_value;
-
- GNUNET_snprintf(parameters, sizeof(parameters), "-d %s", params);
- memset(&start, 0, sizeof(start));
- start.cb = sizeof(start);
- memset(&proc, 0, sizeof(proc));
-
-
- // Start the child process.
- if (!(CreateProcess(
- p, // current windows (2k3 and up can handle / instead of \ in paths))
- parameters, // execute dryrun/priviliege checking mode
- NULL, // Process handle not inheritable
- NULL, // Thread handle not inheritable
- FALSE, // Set handle inheritance to FALSE
- CREATE_DEFAULT_ERROR_MODE, // No creation flags
- NULL, // Use parent's environment block
- NULL, // Use parent's starting directory
- &start, // Pointer to STARTUPINFO structure
- &proc) // Pointer to PROCESS_INFORMATION structure
- ))
- {
- LOG(GNUNET_ERROR_TYPE_ERROR,
- _("CreateProcess failed for binary %s (%d).\n"),
- p,
- GetLastError());
- return GNUNET_SYSERR;
- }
-
- // Wait until child process exits.
- WaitForSingleObject(proc.hProcess, INFINITE);
-
- if (!GetExitCodeProcess(proc.hProcess, &exit_value))
- {
- LOG(GNUNET_ERROR_TYPE_ERROR,
- _("GetExitCodeProcess failed for binary %s (%d).\n"),
- p,
- GetLastError());
- return GNUNET_SYSERR;
- }
- // Close process and thread handles.
- CloseHandle(proc.hProcess);
- CloseHandle(proc.hThread);
-
- if (!exit_value)
- return GNUNET_YES;
-#endif
}
GNUNET_free(p);
return GNUNET_NO;
diff --git a/src/util/os_network.c b/src/util/os_network.c
index 4df37b9e5..526678047 100644
--- a/src/util/os_network.c
+++ b/src/util/os_network.c
@@ -35,7 +35,7 @@
#define LOG_STRERROR_FILE(kind, syscall, filename) GNUNET_log_from_strerror_file(kind, "util-os-network", syscall, filename)
-#if !(HAVE_GETIFADDRS && HAVE_FREEIFADDRS) && !MINGW
+#if !(HAVE_GETIFADDRS && HAVE_FREEIFADDRS)
/**
* Try to enumerate all network interfaces using 'ifconfig'.
*
@@ -388,32 +388,7 @@ void
GNUNET_OS_network_interfaces_list(GNUNET_OS_NetworkInterfaceProcessor proc,
void *proc_cls)
{
-#ifdef MINGW
- int r;
- int i;
- struct EnumNICs3_results *results = NULL;
- int results_count;
-
- r = EnumNICs3(&results, &results_count);
- if (r != GNUNET_OK)
- return;
-
- for (i = 0; i < results_count; i++)
- {
- if (GNUNET_OK !=
- proc(proc_cls, results[i].pretty_name, results[i].is_default,
- (const struct sockaddr *)&results[i].address,
- results[i].
- flags & ENUMNICS3_BCAST_OK ?
- (const struct sockaddr *)&results[i].broadcast : NULL,
- results[i].flags & ENUMNICS3_MASK_OK ?
- (const struct sockaddr *)&results[i].mask : NULL,
- results[i].addr_size))
- break;
- }
- EnumNICs3_free(results);
- return;
-#elif HAVE_GETIFADDRS && HAVE_FREEIFADDRS
+#if HAVE_GETIFADDRS && HAVE_FREEIFADDRS
struct ifaddrs *ifa_first;
struct ifaddrs *ifa_ptr;
socklen_t alen;
diff --git a/src/util/os_priority.c b/src/util/os_priority.c
index ebe469b3b..e25623af5 100644
--- a/src/util/os_priority.c
+++ b/src/util/os_priority.c
@@ -350,7 +350,6 @@ start_process(int pipe_control,
const char *filename,
char *const argv[])
{
-#ifndef MINGW
pid_t ret;
char fds[16];
struct GNUNET_OS_Process *gnunet_proc;
@@ -464,7 +463,7 @@ start_process(int pipe_control,
GNUNET_array_append(lscp, ls, -1);
}
#if DARWIN
- /* see https://gnunet.org/vfork */
+ /* see https://web.archive.org/web/20150924082249/gnunet.org/vfork */
ret = vfork();
#else
ret = fork();
@@ -589,547 +588,6 @@ start_process(int pipe_control,
execvp(filename, argv);
LOG_STRERROR_FILE(GNUNET_ERROR_TYPE_ERROR, "execvp", filename);
_exit(1);
-#else
- struct GNUNET_DISK_FileHandle *childpipe_read;
- struct GNUNET_DISK_FileHandle *childpipe_write;
- HANDLE childpipe_read_handle;
- char **arg;
- char **non_const_argv;
- unsigned int cmdlen;
- char *cmd;
- char *idx;
- STARTUPINFOW start;
- PROCESS_INFORMATION proc;
- int argcount = 0;
- struct GNUNET_OS_Process *gnunet_proc;
- char path[MAX_PATH + 1];
- char *our_env[7] = { NULL, NULL, NULL, NULL, NULL, NULL, NULL };
- char *env_block = NULL;
- char *pathbuf;
- DWORD pathbuf_len;
- DWORD alloc_len;
- char *self_prefix;
- char *bindir;
- char *libdir;
- char *ptr;
- char *non_const_filename;
- char win_path[MAX_PATH + 1];
- struct GNUNET_DISK_PipeHandle *lsocks_pipe;
- const struct GNUNET_DISK_FileHandle *lsocks_write_fd;
- HANDLE lsocks_read;
- HANDLE lsocks_write;
- wchar_t *wpath;
- wchar_t *wcmd;
- size_t wpath_len;
- size_t wcmd_len;
- int env_off;
- int fail;
- long lRet;
- HANDLE stdin_handle;
- HANDLE stdout_handle;
- HANDLE stdih, stdoh, stdeh;
- DWORD stdif, stdof, stdef;
- BOOL bresult;
- DWORD error_code;
- DWORD create_no_window;
-
- if (GNUNET_SYSERR ==
- GNUNET_OS_check_helper_binary(filename, GNUNET_NO, NULL))
- return NULL; /* not executable */
-
- /* Search in prefix dir (hopefully - the directory from which
- * the current module was loaded), bindir and libdir, then in PATH
- */
- self_prefix = GNUNET_OS_installation_get_path(GNUNET_OS_IPK_SELF_PREFIX);
- bindir = GNUNET_OS_installation_get_path(GNUNET_OS_IPK_BINDIR);
- libdir = GNUNET_OS_installation_get_path(GNUNET_OS_IPK_LIBDIR);
-
- pathbuf_len = GetEnvironmentVariableA("PATH", (char *)&pathbuf, 0);
-
- alloc_len = pathbuf_len + 1 + strlen(self_prefix) + 1 + strlen(bindir) + 1 +
- strlen(libdir);
-
- pathbuf = GNUNET_malloc(alloc_len * sizeof(char));
-
- ptr = pathbuf;
- ptr += sprintf(pathbuf, "%s;%s;%s;", self_prefix, bindir, libdir);
- GNUNET_free(self_prefix);
- GNUNET_free(bindir);
- GNUNET_free(libdir);
-
- alloc_len = GetEnvironmentVariableA("PATH", ptr, pathbuf_len);
- if (alloc_len != pathbuf_len - 1)
- {
- GNUNET_free(pathbuf);
- errno = ENOSYS; /* PATH changed on the fly. What kind of error is that? */
- return NULL;
- }
-
- cmdlen = strlen(filename);
- if ((cmdlen < 5) || (0 != strcmp(&filename[cmdlen - 4], ".exe")))
- GNUNET_asprintf(&non_const_filename, "%s.exe", filename);
- else
- GNUNET_asprintf(&non_const_filename, "%s", filename);
-
- /* It could be in POSIX form, convert it to a DOS path early on */
- if (ERROR_SUCCESS !=
- (lRet = plibc_conv_to_win_path(non_const_filename, win_path)))
- {
- SetErrnoFromWinError(lRet);
- LOG_STRERROR_FILE(GNUNET_ERROR_TYPE_ERROR,
- "plibc_conv_to_win_path",
- non_const_filename);
- GNUNET_free(non_const_filename);
- GNUNET_free(pathbuf);
- return NULL;
- }
- GNUNET_free(non_const_filename);
- non_const_filename = GNUNET_strdup(win_path);
- /* Check that this is the full path. If it isn't, search. */
- /* FIXME: convert it to wchar_t and use SearchPathW?
- * Remember: arguments to _start_process() are technically in UTF-8...
- */
- if (non_const_filename[1] == ':')
- {
- snprintf(path, sizeof(path) / sizeof(char), "%s", non_const_filename);
- LOG(GNUNET_ERROR_TYPE_DEBUG,
- "Using path `%s' as-is. PATH is %s\n",
- path,
- ptr);
- }
- else if (!SearchPathA(pathbuf,
- non_const_filename,
- NULL,
- sizeof(path) / sizeof(char),
- path,
- NULL))
- {
- SetErrnoFromWinError(GetLastError());
- LOG_STRERROR_FILE(GNUNET_ERROR_TYPE_ERROR,
- "SearchPath",
- non_const_filename);
- GNUNET_free(non_const_filename);
- GNUNET_free(pathbuf);
- return NULL;
- }
- else
- LOG(GNUNET_ERROR_TYPE_DEBUG, "Found `%s' in PATH `%s'\n", path, pathbuf);
- GNUNET_free(pathbuf);
- GNUNET_free(non_const_filename);
-
- /* Count the number of arguments */
- arg = (char **)argv;
- while (*arg)
- {
- arg++;
- argcount++;
- }
-
- /* Allocate a copy argv */
- non_const_argv = GNUNET_malloc(sizeof(char *) * (argcount + 1));
-
- /* Copy all argv strings */
- argcount = 0;
- arg = (char **)argv;
- while (*arg)
- {
- if (arg == argv)
- non_const_argv[argcount] = GNUNET_strdup(path);
- else
- non_const_argv[argcount] = GNUNET_strdup(*arg);
- arg++;
- argcount++;
- }
- non_const_argv[argcount] = NULL;
-
- /* Count cmd len */
- cmdlen = 1;
- arg = non_const_argv;
- while (*arg)
- {
- cmdlen = cmdlen + strlen(*arg) + 4;
- arg++;
- }
-
- /* Allocate and create cmd */
- cmd = idx = GNUNET_malloc(sizeof(char) * cmdlen);
- arg = non_const_argv;
- while (*arg)
- {
- char arg_last_char = (*arg)[strlen(*arg) - 1];
- idx += sprintf(idx,
- "\"%s%s\"%s",
- *arg,
- arg_last_char == '\\' ? "\\" : "",
- *(arg + 1) ? " " : "");
- arg++;
- }
-
- while (argcount > 0)
- GNUNET_free(non_const_argv[--argcount]);
- GNUNET_free(non_const_argv);
-
- memset(&start, 0, sizeof(start));
- start.cb = sizeof(start);
- if ((pipe_stdin != NULL) || (pipe_stdout != NULL) || (std_inheritance != 0))
- start.dwFlags |= STARTF_USESTDHANDLES;
-
- stdih = GetStdHandle(STD_INPUT_HANDLE);
- GetHandleInformation(stdih, &stdif);
- if (pipe_stdin != NULL)
- {
- GNUNET_DISK_internal_file_handle_(
- GNUNET_DISK_pipe_handle(pipe_stdin, GNUNET_DISK_PIPE_END_READ),
- &stdin_handle,
- sizeof(HANDLE));
- start.hStdInput = stdin_handle;
- }
- else if (stdih)
- {
- if (std_inheritance & GNUNET_OS_INHERIT_STD_IN)
- {
- SetHandleInformation(stdih, HANDLE_FLAG_INHERIT, 1);
- if (pipe_stdin == NULL)
- start.hStdInput = stdih;
- }
- else
- SetHandleInformation(stdih, HANDLE_FLAG_INHERIT, 0);
- }
-
-
- stdoh = GetStdHandle(STD_OUTPUT_HANDLE);
- GetHandleInformation(stdoh, &stdof);
- if (NULL != pipe_stdout)
- {
- GNUNET_DISK_internal_file_handle_(
- GNUNET_DISK_pipe_handle(pipe_stdout, GNUNET_DISK_PIPE_END_WRITE),
- &stdout_handle,
- sizeof(HANDLE));
- start.hStdOutput = stdout_handle;
- }
- else if (stdoh)
- {
- if (std_inheritance & GNUNET_OS_INHERIT_STD_OUT)
- {
- SetHandleInformation(stdoh, HANDLE_FLAG_INHERIT, 1);
- if (pipe_stdout == NULL)
- start.hStdOutput = stdoh;
- }
- else
- SetHandleInformation(stdoh, HANDLE_FLAG_INHERIT, 0);
- }
-
- stdeh = GetStdHandle(STD_ERROR_HANDLE);
- GetHandleInformation(stdeh, &stdef);
- if (stdeh)
- {
- if (std_inheritance & GNUNET_OS_INHERIT_STD_ERR)
- {
- SetHandleInformation(stdeh, HANDLE_FLAG_INHERIT, 1);
- start.hStdError = stdeh;
- }
- else
- SetHandleInformation(stdeh, HANDLE_FLAG_INHERIT, 0);
- }
-
- if (GNUNET_YES == pipe_control)
- {
- struct GNUNET_DISK_PipeHandle *childpipe;
- childpipe = GNUNET_DISK_pipe(GNUNET_NO, GNUNET_NO, GNUNET_YES, GNUNET_NO);
- if (NULL == childpipe)
- return NULL;
- childpipe_read =
- GNUNET_DISK_pipe_detach_end(childpipe, GNUNET_DISK_PIPE_END_READ);
- childpipe_write =
- GNUNET_DISK_pipe_detach_end(childpipe, GNUNET_DISK_PIPE_END_WRITE);
- GNUNET_DISK_pipe_close(childpipe);
- if ((NULL == childpipe_read) || (NULL == childpipe_write) ||
- (GNUNET_OK != GNUNET_DISK_internal_file_handle_(childpipe_read,
- &childpipe_read_handle,
- sizeof(HANDLE))))
- {
- if (childpipe_read)
- GNUNET_DISK_file_close(childpipe_read);
- if (childpipe_write)
- GNUNET_DISK_file_close(childpipe_write);
- GNUNET_free(cmd);
- return NULL;
- }
- /* Unlike *nix variant, we don't dup the handle, so can't close
- * filehandle right now.
- */
- SetHandleInformation(childpipe_read_handle, HANDLE_FLAG_INHERIT, 1);
- }
- else
- {
- childpipe_read = NULL;
- childpipe_write = NULL;
- }
-
- if (lsocks != NULL && lsocks[0] != INVALID_SOCKET)
- {
- lsocks_pipe =
- GNUNET_DISK_pipe(GNUNET_YES, GNUNET_YES, GNUNET_YES, GNUNET_NO);
-
- if (lsocks_pipe == NULL)
- {
- GNUNET_free(cmd);
- GNUNET_DISK_pipe_close(lsocks_pipe);
- if (GNUNET_YES == pipe_control)
- {
- GNUNET_DISK_file_close(childpipe_write);
- GNUNET_DISK_file_close(childpipe_read);
- }
- return NULL;
- }
- lsocks_write_fd =
- GNUNET_DISK_pipe_handle(lsocks_pipe, GNUNET_DISK_PIPE_END_WRITE);
- GNUNET_DISK_internal_file_handle_(lsocks_write_fd,
- &lsocks_write,
- sizeof(HANDLE));
- GNUNET_DISK_internal_file_handle_(
- GNUNET_DISK_pipe_handle(lsocks_pipe, GNUNET_DISK_PIPE_END_READ),
- &lsocks_read,
- sizeof(HANDLE));
- }
- else
- {
- lsocks_pipe = NULL;
- lsocks_write_fd = NULL;
- }
-
- env_off = 0;
- if (GNUNET_YES == pipe_control)
- {
- GNUNET_asprintf(&our_env[env_off++], "%s=", GNUNET_OS_CONTROL_PIPE);
- GNUNET_asprintf(&our_env[env_off++], "%p", childpipe_read_handle);
- }
- if ((lsocks != NULL) && (lsocks[0] != INVALID_SOCKET))
- {
- /*This will tell the child that we're going to send lsocks over the pipe*/
- GNUNET_asprintf(&our_env[env_off++], "%s=", "GNUNET_OS_READ_LSOCKS");
- GNUNET_asprintf(&our_env[env_off++], "%lu", lsocks_read);
- }
- our_env[env_off++] = NULL;
- env_block = CreateCustomEnvTable(our_env);
- while (0 > env_off)
- GNUNET_free_non_null(our_env[--env_off]);
-
- wpath_len = 0;
- if (NULL ==
- (wpath =
- u8_to_u16((uint8_t *)path, 1 + strlen(path), NULL, &wpath_len)))
- {
- LOG(GNUNET_ERROR_TYPE_DEBUG,
- "Failed to convert `%s' from UTF-8 to UTF-16: %d\n",
- path,
- errno);
- GNUNET_free(env_block);
- GNUNET_free(cmd);
- if (lsocks_pipe)
- GNUNET_DISK_pipe_close(lsocks_pipe);
- if (GNUNET_YES == pipe_control)
- {
- GNUNET_DISK_file_close(childpipe_write);
- GNUNET_DISK_file_close(childpipe_read);
- }
- return NULL;
- }
-
- wcmd_len = 0;
- if (NULL ==
- (wcmd = u8_to_u16((uint8_t *)cmd, 1 + strlen(cmd), NULL, &wcmd_len)))
- {
- LOG(GNUNET_ERROR_TYPE_DEBUG,
- "Failed to convert `%s' from UTF-8 to UTF-16: %d\n",
- cmd,
- errno);
- GNUNET_free(env_block);
- GNUNET_free(cmd);
- free(wpath);
- if (lsocks_pipe)
- GNUNET_DISK_pipe_close(lsocks_pipe);
- if (GNUNET_YES == pipe_control)
- {
- GNUNET_DISK_file_close(childpipe_write);
- GNUNET_DISK_file_close(childpipe_read);
- }
- return NULL;
- }
-
- create_no_window = 0;
- {
- HANDLE console_input = CreateFile("CONIN$",
- GENERIC_READ,
- FILE_SHARE_READ | FILE_SHARE_WRITE,
- NULL,
- OPEN_EXISTING,
- 0,
- NULL);
- if (INVALID_HANDLE_VALUE == console_input)
- create_no_window = CREATE_NO_WINDOW;
- else
- CloseHandle(console_input);
- }
-
- bresult = CreateProcessW(wpath,
- wcmd,
- NULL,
- NULL,
- GNUNET_YES,
- create_no_window | CREATE_SUSPENDED,
- env_block,
- NULL,
- &start,
- &proc);
- error_code = GetLastError();
-
- if ((NULL == pipe_stdin) && (stdih))
- SetHandleInformation(stdih, HANDLE_FLAG_INHERIT, stdif);
-
-
- if ((NULL == pipe_stdout) && (stdoh))
- SetHandleInformation(stdoh, HANDLE_FLAG_INHERIT, stdof);
-
- if (stdeh)
- SetHandleInformation(stdeh, HANDLE_FLAG_INHERIT, stdef);
-
- if (!bresult)
- LOG(GNUNET_ERROR_TYPE_ERROR,
- "CreateProcess(%s, %s) failed: %lu\n",
- path,
- cmd,
- error_code);
-
- GNUNET_free(env_block);
- GNUNET_free(cmd);
- free(wpath);
- free(wcmd);
- if (GNUNET_YES == pipe_control)
- {
- GNUNET_DISK_file_close(childpipe_read);
- }
-
- if (!bresult)
- {
- if (GNUNET_YES == pipe_control)
- {
- GNUNET_DISK_file_close(childpipe_write);
- }
- if (NULL != lsocks)
- GNUNET_DISK_pipe_close(lsocks_pipe);
- SetErrnoFromWinError(error_code);
- return NULL;
- }
-
- gnunet_proc = GNUNET_new(struct GNUNET_OS_Process);
- gnunet_proc->pid = proc.dwProcessId;
- gnunet_proc->handle = proc.hProcess;
- gnunet_proc->control_pipe = childpipe_write;
-
- CreateThread(NULL, 64000, &child_wait_thread, (void *)gnunet_proc, 0, NULL);
-
- ResumeThread(proc.hThread);
- CloseHandle(proc.hThread);
-
- if ((NULL == lsocks) || (INVALID_SOCKET == lsocks[0]))
- return gnunet_proc;
-
- GNUNET_DISK_pipe_close_end(lsocks_pipe, GNUNET_DISK_PIPE_END_READ);
-
- /* This is a replacement for "goto error" that doesn't use goto */
- fail = 1;
- do
- {
- ssize_t wrote;
- uint64_t size;
- uint64_t count;
- unsigned int i;
-
- /* Tell the number of sockets */
- for (count = 0; lsocks && lsocks[count] != INVALID_SOCKET; count++)
- ;
-
- wrote = GNUNET_DISK_file_write(lsocks_write_fd, &count, sizeof(count));
- if (sizeof(count) != wrote)
- {
- GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
- "Failed to write %u count bytes to the child: %lu\n",
- sizeof(count),
- GetLastError());
- break;
- }
- for (i = 0; lsocks && lsocks[i] != INVALID_SOCKET; i++)
- {
- WSAPROTOCOL_INFOA pi;
- /* Get a socket duplication info */
- if (SOCKET_ERROR ==
- WSADuplicateSocketA(lsocks[i], gnunet_proc->pid, &pi))
- {
- GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
- "Failed to duplicate an socket[%u]: %lu\n",
- i,
- GetLastError());
- break;
- }
- /* Synchronous I/O is not nice, but we can't schedule this:
- * lsocks will be closed/freed by the caller soon, and until
- * the child creates a duplicate, closing a socket here will
- * close it for good.
- */
- /* Send the size of the structure
- * (the child might be built with different headers...)
- */
- size = sizeof(pi);
- wrote = GNUNET_DISK_file_write(lsocks_write_fd, &size, sizeof(size));
- if (sizeof(size) != wrote)
- {
- GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
- "Failed to write %u size[%u] bytes to the child: %lu\n",
- sizeof(size),
- i,
- GetLastError());
- break;
- }
- /* Finally! Send the data */
- wrote = GNUNET_DISK_file_write(lsocks_write_fd, &pi, sizeof(pi));
- if (sizeof(pi) != wrote)
- {
- GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
- "Failed to write %u socket[%u] bytes to the child: %lu\n",
- sizeof(pi),
- i,
- GetLastError());
- break;
- }
- }
- /* This will block us until the child makes a final read or closes
- * the pipe (hence no 'wrote' check), since we have to wait for it
- * to duplicate the last socket, before we return and start closing
- * our own copies)
- */
- wrote = GNUNET_DISK_file_write(lsocks_write_fd, &count, sizeof(count));
- fail = 0;
- }
- while (fail);
-
- GNUNET_DISK_file_sync(lsocks_write_fd);
- GNUNET_DISK_pipe_close(lsocks_pipe);
-
- if (fail)
- {
- /* If we can't pass on the socket(s), the child will block forever,
- * better put it out of its misery.
- */
- SafeTerminateProcess(gnunet_proc->handle, 0, 0);
- CloseHandle(gnunet_proc->handle);
- if (NULL != gnunet_proc->control_pipe)
- GNUNET_DISK_file_close(gnunet_proc->control_pipe);
- GNUNET_free(gnunet_proc);
- return NULL;
- }
- return gnunet_proc;
-#endif
}
@@ -1439,7 +897,6 @@ process_status(struct GNUNET_OS_Process *proc,
unsigned long *code,
int options)
{
-#ifndef MINGW
int status;
int ret;
@@ -1488,53 +945,6 @@ process_status(struct GNUNET_OS_Process *proc,
*type = GNUNET_OS_PROCESS_UNKNOWN;
*code = 0;
}
-#else
-#ifndef WNOHANG
-#define WNOHANG 42 /* just a flag for W32, purely internal at this point */
-#endif
-
- HANDLE h;
- DWORD c, error_code, ret;
-
- h = proc->handle;
- ret = proc->pid;
- if (h == NULL || ret == 0)
- {
- LOG(GNUNET_ERROR_TYPE_WARNING,
- "Invalid process information {%d, %08X}\n",
- ret,
- h);
- return GNUNET_SYSERR;
- }
- if (h == NULL)
- h = GetCurrentProcess();
-
- if (WNOHANG != options)
- {
- if (WAIT_OBJECT_0 != WaitForSingleObject(h, INFINITE))
- {
- SetErrnoFromWinError(GetLastError());
- return GNUNET_SYSERR;
- }
- }
- SetLastError(0);
- ret = GetExitCodeProcess(h, &c);
- error_code = GetLastError();
- if (ret == 0 || error_code != NO_ERROR)
- {
- SetErrnoFromWinError(error_code);
- LOG_STRERROR(GNUNET_ERROR_TYPE_WARNING, "GetExitCodeProcess");
- return GNUNET_SYSERR;
- }
- if (STILL_ACTIVE == c)
- {
- *type = GNUNET_OS_PROCESS_RUNNING;
- *code = 0;
- return GNUNET_NO;
- }
- *type = GNUNET_OS_PROCESS_EXITED;
- *code = c;
-#endif
return GNUNET_OK;
}
@@ -1589,7 +999,6 @@ GNUNET_OS_process_wait_status(struct GNUNET_OS_Process *proc,
int
GNUNET_OS_process_wait(struct GNUNET_OS_Process *proc)
{
-#ifndef MINGW
pid_t pid = proc->pid;
pid_t ret;
@@ -1601,28 +1010,6 @@ GNUNET_OS_process_wait(struct GNUNET_OS_Process *proc)
return GNUNET_SYSERR;
}
return GNUNET_OK;
-#else
- HANDLE h;
-
- h = proc->handle;
- if (NULL == h)
- {
- LOG(GNUNET_ERROR_TYPE_WARNING,
- "Invalid process information {%d, %08X}\n",
- proc->pid,
- h);
- return GNUNET_SYSERR;
- }
- if (NULL == h)
- h = GetCurrentProcess();
-
- if (WAIT_OBJECT_0 != WaitForSingleObject(h, INFINITE))
- {
- SetErrnoFromWinError(GetLastError());
- return GNUNET_SYSERR;
- }
- return GNUNET_OK;
-#endif
}
diff --git a/src/util/scheduler.c b/src/util/scheduler.c
index 4bea5bd5d..f379bce42 100644
--- a/src/util/scheduler.c
+++ b/src/util/scheduler.c
@@ -108,7 +108,6 @@ struct GNUNET_SCHEDULER_Handle {
struct GNUNET_SIGNAL_Context *shc_gterm;
#endif
-#ifndef MINGW
/**
* context of the SIGQUIT handler
*/
@@ -123,7 +122,6 @@ struct GNUNET_SCHEDULER_Handle {
* context of hte SIGPIPE handler
*/
struct GNUNET_SIGNAL_Context *shc_pipe;
-#endif
};
@@ -621,13 +619,11 @@ static pid_t my_pid;
/**
* Signal handler called for SIGPIPE.
*/
-#ifndef MINGW
static void
sighandler_pipe()
{
return;
}
-#endif
///**
@@ -1396,7 +1392,6 @@ check_fd(struct GNUNET_SCHEDULER_Task *t, int raw_fd)
* @return unique task identifier for the job
* only valid until @a task is started!
*/
-#ifndef MINGW
static struct GNUNET_SCHEDULER_Task *
add_without_sets(struct GNUNET_TIME_Relative delay,
enum GNUNET_SCHEDULER_Priority priority,
@@ -1446,7 +1441,6 @@ add_without_sets(struct GNUNET_TIME_Relative delay,
init_backtrace(t);
return t;
}
-#endif
/**
@@ -1586,22 +1580,6 @@ GNUNET_SCHEDULER_add_net_with_priority(struct GNUNET_TIME_Relative delay,
{
/* scheduler must be running */
GNUNET_assert(NULL != scheduler_driver);
-
-#if MINGW
- struct GNUNET_NETWORK_FDSet *s;
- struct GNUNET_SCHEDULER_Task * ret;
-
- GNUNET_assert(NULL != fd);
- s = GNUNET_NETWORK_fdset_create();
- GNUNET_NETWORK_fdset_set(s, fd);
- ret = GNUNET_SCHEDULER_add_select(
- priority, delay,
- on_read ? s : NULL,
- on_write ? s : NULL,
- task, task_cls);
- GNUNET_NETWORK_fdset_destroy(s);
- return ret;
-#else
GNUNET_assert(on_read || on_write);
GNUNET_assert(GNUNET_NETWORK_get_fd(fd) >= 0);
return add_without_sets(delay, priority,
@@ -1610,7 +1588,6 @@ GNUNET_SCHEDULER_add_net_with_priority(struct GNUNET_TIME_Relative delay,
NULL,
NULL,
task, task_cls);
-#endif
}
@@ -1710,22 +1687,6 @@ GNUNET_SCHEDULER_add_file_with_priority(struct GNUNET_TIME_Relative delay,
{
/* scheduler must be running */
GNUNET_assert(NULL != scheduler_driver);
-
-#if MINGW
- struct GNUNET_NETWORK_FDSet *s;
- struct GNUNET_SCHEDULER_Task * ret;
-
- GNUNET_assert(NULL != fd);
- s = GNUNET_NETWORK_fdset_create();
- GNUNET_NETWORK_fdset_handle_set(s, fd);
- ret = GNUNET_SCHEDULER_add_select(
- priority, delay,
- on_read ? s : NULL,
- on_write ? s : NULL,
- task, task_cls);
- GNUNET_NETWORK_fdset_destroy(s);
- return ret;
-#else
GNUNET_assert(on_read || on_write);
GNUNET_assert(fd->fd >= 0);
return add_without_sets(delay, priority,
@@ -1734,7 +1695,6 @@ GNUNET_SCHEDULER_add_file_with_priority(struct GNUNET_TIME_Relative delay,
on_read ? fd : NULL,
on_write ? fd : NULL,
task, task_cls);
-#endif
}
@@ -2218,14 +2178,12 @@ GNUNET_SCHEDULER_driver_init(const struct GNUNET_SCHEDULER_Driver *driver)
sh->shc_gterm = GNUNET_SIGNAL_handler_install(GNUNET_TERM_SIG,
&sighandler_shutdown);
#endif
-#ifndef MINGW
sh->shc_pipe = GNUNET_SIGNAL_handler_install(SIGPIPE,
&sighandler_pipe);
sh->shc_quit = GNUNET_SIGNAL_handler_install(SIGQUIT,
&sighandler_shutdown);
sh->shc_hup = GNUNET_SIGNAL_handler_install(SIGHUP,
&sighandler_shutdown);
-#endif
/* Setup initial tasks */
current_priority = GNUNET_SCHEDULER_PRIORITY_DEFAULT;
@@ -2282,11 +2240,9 @@ GNUNET_SCHEDULER_driver_done(struct GNUNET_SCHEDULER_Handle *sh)
#if (SIGTERM != GNUNET_TERM_SIG)
GNUNET_SIGNAL_handler_uninstall(sh->shc_gterm);
#endif
-#ifndef MINGW
GNUNET_SIGNAL_handler_uninstall(sh->shc_pipe);
GNUNET_SIGNAL_handler_uninstall(sh->shc_quit);
GNUNET_SIGNAL_handler_uninstall(sh->shc_hup);
-#endif
GNUNET_DISK_pipe_close(shutdown_pipe_handle);
shutdown_pipe_handle = NULL;
scheduler_driver = NULL;
@@ -2352,7 +2308,6 @@ select_loop(struct GNUNET_SCHEDULER_Handle *sh,
LOG_STRERROR(GNUNET_ERROR_TYPE_ERROR,
"select");
-#ifndef MINGW
#if USE_LSOF
char lsof[512];
@@ -2366,7 +2321,6 @@ select_loop(struct GNUNET_SCHEDULER_Handle *sh,
LOG_STRERROR(GNUNET_ERROR_TYPE_WARNING,
"system");
#endif
-#endif
#if DEBUG_FDS
for (struct Scheduled *s = context->scheduled_head;
NULL != s;
diff --git a/src/util/service.c b/src/util/service.c
index 880047a42..b0f4ea289 100644
--- a/src/util/service.c
+++ b/src/util/service.c
@@ -1354,93 +1354,6 @@ get_server_addresses(const char *service_name,
}
-#ifdef MINGW
-/**
- * Read listen sockets from the parent process (ARM).
- *
- * @param sh service context to initialize
- * @return NULL-terminated array of sockets on success,
- * NULL if not ok (must bind yourself)
- */
-static struct GNUNET_NETWORK_Handle **
-receive_sockets_from_parent(struct GNUNET_SERVICE_Handle *sh)
-{
- static struct GNUNET_NETWORK_Handle **lsocks;
- const char *env_buf;
- int fail;
- uint64_t count;
- uint64_t i;
- HANDLE lsocks_pipe;
-
- env_buf = getenv("GNUNET_OS_READ_LSOCKS");
- if ((NULL == env_buf) || (strlen(env_buf) <= 0))
- return NULL;
- /* Using W32 API directly here, because this pipe will
- * never be used outside of this function, and it's just too much of a bother
- * to create a GNUnet API that boxes a HANDLE (the way it is done with socks)
- */
- lsocks_pipe = (HANDLE)strtoul(env_buf, NULL, 10);
- if ((0 == lsocks_pipe) || (INVALID_HANDLE_VALUE == lsocks_pipe))
- return NULL;
- fail = 1;
- do
- {
- int ret;
- int fail2;
- DWORD rd;
-
- ret = ReadFile(lsocks_pipe, &count, sizeof(count), &rd, NULL);
- if ((0 == ret) || (sizeof(count) != rd) || (0 == count))
- break;
- lsocks = GNUNET_new_array(count + 1, struct GNUNET_NETWORK_Handle *);
-
- fail2 = 1;
- for (i = 0; i < count; i++)
- {
- WSAPROTOCOL_INFOA pi;
- uint64_t size;
- _win_socket s;
-
- ret = ReadFile(lsocks_pipe, &size, sizeof(size), &rd, NULL);
- if ((0 == ret) || (sizeof(size) != rd) || (sizeof(pi) != size))
- break;
- ret = ReadFile(lsocks_pipe, &pi, sizeof(pi), &rd, NULL);
- if ((0 == ret) || (sizeof(pi) != rd))
- break;
- s = WSASocketA(pi.iAddressFamily,
- pi.iSocketType,
- pi.iProtocol,
- &pi,
- 0,
- WSA_FLAG_OVERLAPPED);
- lsocks[i] = GNUNET_NETWORK_socket_box_native(s);
- if (NULL == lsocks[i])
- break;
- else if (i == count - 1)
- fail2 = 0;
- }
- if (fail2)
- break;
- lsocks[count] = NULL;
- fail = 0;
- }
- while (fail);
- CloseHandle(lsocks_pipe);
-
- if (fail)
- {
- LOG(GNUNET_ERROR_TYPE_ERROR,
- _("Could not access a pre-bound socket, will try to bind myself\n"));
- for (i = 0; (i < count) && (NULL != lsocks[i]); i++)
- GNUNET_break(GNUNET_OK == GNUNET_NETWORK_socket_close(lsocks[i]));
- GNUNET_free(lsocks);
- return NULL;
- }
- return lsocks;
-}
-#endif
-
-
/**
* Create and initialize a listen socket for the server.
*
@@ -1557,13 +1470,10 @@ setup_service(struct GNUNET_SERVICE_Handle *sh)
{
int tolerant;
struct GNUNET_NETWORK_Handle **lsocks;
-
-#ifndef MINGW
const char *nfds;
unsigned int cnt;
int flags;
char dummy[2];
-#endif
if (GNUNET_CONFIGURATION_have_value(sh->cfg, sh->service_name, "TOLERANT"))
{
@@ -1583,7 +1493,7 @@ setup_service(struct GNUNET_SERVICE_Handle *sh)
tolerant = GNUNET_NO;
lsocks = NULL;
-#ifndef MINGW
+
errno = 0;
if ((NULL != (nfds = getenv("LISTEN_FDS"))) &&
(1 == sscanf(nfds, "%u%1s", &cnt, dummy)) && (cnt > 0) &&
@@ -1611,13 +1521,6 @@ setup_service(struct GNUNET_SERVICE_Handle *sh)
}
unsetenv("LISTEN_FDS");
}
-#else
- if (NULL != getenv("GNUNET_OS_READ_LSOCKS"))
- {
- lsocks = receive_sockets_from_parent(sh);
- putenv("GNUNET_OS_READ_LSOCKS=");
- }
-#endif
if (NULL != lsocks)
{
@@ -1723,7 +1626,7 @@ set_user_id(struct GNUNET_SERVICE_Handle *sh)
if (NULL == (user = get_user_name(sh)))
return GNUNET_OK; /* keep */
-#ifndef MINGW
+
struct passwd *pws;
errno = 0;
@@ -1754,7 +1657,7 @@ set_user_id(struct GNUNET_SERVICE_Handle *sh)
return GNUNET_SYSERR;
}
}
-#endif
+
GNUNET_free(user);
return GNUNET_OK;
}
@@ -1808,7 +1711,6 @@ pid_file_delete(struct GNUNET_SERVICE_Handle *sh)
static int
detach_terminal(struct GNUNET_SERVICE_Handle *sh)
{
-#ifndef MINGW
pid_t pid;
int nullfd;
int filedes[2];
@@ -1875,11 +1777,7 @@ detach_terminal(struct GNUNET_SERVICE_Handle *sh)
if (-1 == pid)
LOG_STRERROR(GNUNET_ERROR_TYPE_ERROR, "setsid");
sh->ready_confirm_fd = filedes[1];
-#else
- /* FIXME: we probably need to do something else
- * elsewhere in order to fork the process itself... */
- FreeConsole();
-#endif
+
return GNUNET_OK;
}
diff --git a/src/util/strings.c b/src/util/strings.c
index dc46ad33a..25b09f8e2 100644
--- a/src/util/strings.c
+++ b/src/util/strings.c
@@ -602,20 +602,13 @@ char *
GNUNET_STRINGS_filename_expand(const char *fil)
{
char *buffer;
-
-#ifndef MINGW
size_t len;
char *fm;
const char *fil_ptr;
-#else
- char *fn;
- long lRet;
-#endif
if (fil == NULL)
return NULL;
-#ifndef MINGW
if (fil[0] == DIR_SEPARATOR)
/* absolute path, just copy */
return GNUNET_strdup(fil);
@@ -677,34 +670,6 @@ GNUNET_STRINGS_filename_expand(const char *fil)
fil_ptr);
GNUNET_free(fm);
return buffer;
-#else
- fn = GNUNET_malloc(MAX_PATH + 1);
-
- if ((lRet = plibc_conv_to_win_path(fil, fn)) != ERROR_SUCCESS)
- {
- SetErrnoFromWinError(lRet);
- LOG_STRERROR(GNUNET_ERROR_TYPE_WARNING, "plibc_conv_to_win_path");
- return NULL;
- }
- /* is the path relative? */
- if ((0 != strncmp(fn + 1, ":\\", 2)) && (0 != strncmp(fn, "\\\\", 2)))
- {
- char szCurDir[MAX_PATH + 1];
-
- lRet = GetCurrentDirectory(MAX_PATH + 1, szCurDir);
- if (lRet + strlen(fn) + 1 > (MAX_PATH + 1))
- {
- SetErrnoFromWinError(ERROR_BUFFER_OVERFLOW);
- LOG_STRERROR(GNUNET_ERROR_TYPE_WARNING, "GetCurrentDirectory");
- return NULL;
- }
- GNUNET_asprintf(&buffer, "%s\\%s", szCurDir, fn);
- GNUNET_free(fn);
- fn = buffer;
- }
-
- return fn;
-#endif
}
diff --git a/src/util/test_common_logging_runtime_loglevels.c b/src/util/test_common_logging_runtime_loglevels.c
index 07e2327c9..4ba7b544c 100644
--- a/src/util/test_common_logging_runtime_loglevels.c
+++ b/src/util/test_common_logging_runtime_loglevels.c
@@ -401,11 +401,7 @@ runone()
proc = GNUNET_OS_start_process(GNUNET_NO, GNUNET_OS_INHERIT_STD_OUT_AND_ERR,
NULL, pipe_stdout, NULL,
-#if MINGW
- "test_common_logging_dummy",
-#else
"./test_common_logging_dummy",
-#endif
"test_common_logging_dummy", NULL);
GNUNET_assert(NULL != proc);
putenv("GNUNET_FORCE_LOG=");
diff --git a/src/util/test_configuration.c b/src/util/test_configuration.c
index 71a1ae5bd..b5b1e238c 100644
--- a/src/util/test_configuration.c
+++ b/src/util/test_configuration.c
@@ -323,12 +323,8 @@ testConfig()
GNUNET_break(0);
return 8;
}
-#ifndef MINGW
+
if (0 != strcmp(c, "/hello/world"))
-#else
-#define HI "\\hello\\world"
- if (strstr(c, HI) != c + strlen(c) - strlen(HI))
-#endif
{
GNUNET_break(0);
GNUNET_free(c);
diff --git a/src/util/test_getopt.c b/src/util/test_getopt.c
index 620605f96..77b8c8b2f 100644
--- a/src/util/test_getopt.c
+++ b/src/util/test_getopt.c
@@ -163,9 +163,9 @@ main(int argc, char *argv[])
GNUNET_log_setup("test_getopt", "WARNING", NULL);
/* suppress output from -h, -v options */
-#ifndef MINGW
+
GNUNET_break(0 == close(1));
-#endif
+
if (0 != testMinimal())
errCnt++;
if (0 != testVerbose())
diff --git a/src/util/test_resolver_api.c b/src/util/test_resolver_api.c
index ea26c4ee6..0b27a2eff 100644
--- a/src/util/test_resolver_api.c
+++ b/src/util/test_resolver_api.c
@@ -307,11 +307,8 @@ run(void *cls, char *const *args, const char *cfgfile,
#if HAVE_SOCKADDR_IN_SIN_LEN
sa.sin_len = (u_char)sizeof(sa);
#endif
-#ifndef MINGW
inet_aton(ROOTSERVER_IP, &sa.sin_addr);
-#else
- sa.sin_addr.S_un.S_addr = inet_addr(ROOTSERVER_IP);
-#endif
+
GNUNET_RESOLVER_hostname_get((const struct sockaddr *)&sa,
sizeof(struct sockaddr), GNUNET_YES, timeout,
&check_rootserver_name, cls);
diff --git a/src/util/test_scheduler.c b/src/util/test_scheduler.c
index 236bb4e76..8952225c2 100644
--- a/src/util/test_scheduler.c
+++ b/src/util/test_scheduler.c
@@ -211,7 +211,6 @@ checkShutdown()
}
-#ifndef MINGW
static void
taskSig(void *cls)
{
@@ -244,7 +243,6 @@ checkSignal()
GNUNET_SCHEDULER_run(&taskSig, &ok);
return ok;
}
-#endif
static void
@@ -283,9 +281,7 @@ main(int argc, char *argv[])
GNUNET_log_setup("test_scheduler", "WARNING", NULL);
ret += check();
ret += checkCancel();
-#ifndef MINGW
ret += checkSignal();
-#endif
ret += checkShutdown();
GNUNET_DISK_pipe_close(p);
diff --git a/src/util/test_service.c b/src/util/test_service.c
index c0b02872f..4edc38a0d 100644
--- a/src/util/test_service.c
+++ b/src/util/test_service.c
@@ -206,11 +206,10 @@ main(int argc,
NULL);
ret += check("test_service");
ret += check("test_service");
-#ifndef MINGW
s = GNUNET_NETWORK_socket_create(PF_INET6,
SOCK_STREAM,
0);
-#endif
+
if (NULL == s)
{
if ((errno == ENOBUFS) ||
diff --git a/src/util/test_strings.c b/src/util/test_strings.c
index a4e548e31..60887c587 100644
--- a/src/util/test_strings.c
+++ b/src/util/test_strings.c
@@ -67,11 +67,9 @@ main(int argc, char *argv[])
(GNUNET_TIME_UNIT_MILLISECONDS,
7 * 60 * 60 * 1000), GNUNET_YES);
WANTNF(buf, bc);
-#ifndef MINGW
+
hdir = getenv("HOME");
-#else
- hdir = getenv("USERPROFILE");
-#endif
+
GNUNET_snprintf(buf, sizeof(buf), "%s%s", hdir, DIR_SEPARATOR_STR);
b = GNUNET_STRINGS_filename_expand("~");
GNUNET_assert(b != NULL);
diff --git a/src/util/w32cat.c b/src/util/w32cat.c
deleted file mode 100644
index fa7637d38..000000000
--- a/src/util/w32cat.c
+++ /dev/null
@@ -1,154 +0,0 @@
-/*
- W32 version of 'cat' program
- Copyright (C) 2012 LRN
-
- cat is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published
- by the Free Software Foundation; either version 3, or (at your
- option) any later version.
-
- cat is distributed in the hope that it will be useful, but
- WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with cat; see the file COPYING. If not, write to the
- Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
- Boston, MA 02110-1301, USA.
-
- SPDX-License-Identifier: AGPL3.0-or-later
- */
-
-#include <stdio.h>
-#include <windows.h>
-#include <stdint.h>
-#include <signal.h>
-
-DWORD WINAPI
-parent_control_thread(LPVOID lpParameter)
-{
- HANDLE h = (HANDLE)lpParameter;
-
- while (TRUE)
- {
- DWORD dw;
- BOOL b;
- unsigned char c;
- b = ReadFile(h, &c, 1, &dw, NULL);
- if (!b)
- {
- ExitProcess(0);
- }
- raise((int)c);
- }
-}
-
-void
-install_parent_control_handler()
-{
- const char *env_buf;
- char *env_buf_end;
- uint64_t pipe_fd;
- HANDLE pipe_handle;
-
- env_buf = getenv("GNUNET_OS_CONTROL_PIPE");
- if ((NULL == env_buf) || (strlen(env_buf) <= 0))
- return;
- errno = 0;
- pipe_fd = strtoull(env_buf, &env_buf_end, 16);
- if ((0 != errno) || (env_buf == env_buf_end))
- return;
- /* Gcc will issue a warning here. What to do with it? */
- pipe_handle = (HANDLE)(uintptr_t)pipe_fd;
- CreateThread(NULL, 0, parent_control_thread, (LPVOID)pipe_handle, 0, NULL);
-}
-
-int
-main(int argc, char **argv)
-{
- HANDLE stdi, stdo;
- BOOL b;
- wchar_t *commandlinew, **argvw;
- int argcw;
- int i;
-
- stdo = GetStdHandle(STD_OUTPUT_HANDLE);
- if (stdo == INVALID_HANDLE_VALUE || stdo == NULL)
- return 1;
-
- commandlinew = GetCommandLineW();
- argvw = CommandLineToArgvW(commandlinew, &argcw);
- if (argvw == NULL)
- return 1;
-
- install_parent_control_handler();
-
- for (i = 1; i < argcw || argcw == 1; i++)
- {
- DWORD r, w;
- int is_dash = wcscmp(NULL == argvw[i] ? L"-" : argvw[i], L"-") == 0;
- if (argcw == 1 || is_dash)
- {
- stdi = GetStdHandle(STD_INPUT_HANDLE);
- if (stdi == INVALID_HANDLE_VALUE)
- {
- fprintf(stderr, "cat: Failed to obtain stdin handle.\n");
- return 4;
- }
- if (stdi == NULL)
- {
- fprintf(stderr, "cat: Have no stdin.\n");
- return 5;
- }
- }
- else
- {
- stdi = CreateFileW(argvw[i], GENERIC_READ, FILE_SHARE_DELETE | FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, FILE_FLAG_SEQUENTIAL_SCAN, NULL);
- if (stdi == INVALID_HANDLE_VALUE)
- {
- wchar_t *msgbuf;
- DWORD le = GetLastError();
- if (0 < FormatMessageW(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM, 0, le, 0, (wchar_t *)&msgbuf, 0, NULL))
- {
- fprintf(stderr, "cat: Failed to open file `%S'. Error %lu.\n", argvw[i], le);
- return 3;
- }
- fprintf(stderr, "cat: Failed to open file `%S'. Error %lu: %S\n", argvw[i], le, msgbuf);
- if (msgbuf != NULL)
- LocalFree(msgbuf);
- return 2;
- }
- }
- do
- {
- unsigned char c;
- b = ReadFile(stdi, &c, 1, &r, NULL);
- if (b && r > 0)
- {
- b = WriteFile(stdo, &c, 1, &w, NULL);
- if (b == 0)
- {
- wchar_t *msgbuf;
- DWORD le = GetLastError();
- if (0 < FormatMessageW(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM, 0, le, 0, (wchar_t *)&msgbuf, 0, NULL))
- {
- fprintf(stderr, "cat: Failed to write into stdout. Error %lu.\n", le);
- return 3;
- }
- fprintf(stderr, "cat: Failed to write into stdout. Error %lu: %S\n", le, msgbuf);
- if (msgbuf != NULL)
- LocalFree(msgbuf);
- return 6;
- }
- }
- }
- while (b && r > 0);
- if (argcw == 1)
- break;
- if (!is_dash)
- CloseHandle(stdi);
- }
- LocalFree(argvw);
- return 0;
-}
diff --git a/src/util/win.c b/src/util/win.c
deleted file mode 100644
index a2b0d08da..000000000
--- a/src/util/win.c
+++ /dev/null
@@ -1,1365 +0,0 @@
-/*
- This file is part of GNUnet.
- Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006 GNUnet e.V.
-
- GNUnet is free software: you can redistribute it and/or modify it
- under the terms of the GNU Affero General Public License as published
- by the Free Software Foundation, either version 3 of the License,
- or (at your option) any later version.
-
- GNUnet is distributed in the hope that it will be useful, but
- WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- Affero General Public License for more details.
-
- You should have received a copy of the GNU Affero General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>.
-
- SPDX-License-Identifier: AGPL3.0-or-later
- */
-
-/**
- * @file util/win.c
- * @brief Helper functions for MS Windows in C++
- * @author Nils Durner
- */
-
-#ifndef _WIN_C
-#define _WIN_C
-
-#include "winproc.h"
-#include "platform.h"
-#include "gnunet_crypto_lib.h"
-#include "gnunet_common.h"
-#include "gnunet_connection_lib.h"
-
-#include <ntdef.h>
-#ifndef INHERITED_ACE
-#define INHERITED_ACE 0x10
-#endif
-
-int plibc_conv_to_win_path(const char *pszUnix, char *pszWindows);
-
-#define _IP_ADAPTER_UNICAST_ADDRESS_HEAD \
- union { \
- struct { \
- ULONG Length; \
- DWORD Flags; \
- }; \
- };
-
-#define _IP_ADAPTER_UNICAST_ADDRESS_BASE \
- SOCKET_ADDRESS Address; \
- IP_PREFIX_ORIGIN PrefixOrigin; \
- IP_SUFFIX_ORIGIN SuffixOrigin; \
- IP_DAD_STATE DadState; \
- ULONG ValidLifetime; \
- ULONG PreferredLifetime; \
- ULONG LeaseLifetime;
-
-#define _IP_ADAPTER_UNICAST_ADDRESS_ADD_VISTA \
- UINT8 OnLinkPrefixLength;
-
-
-#define _IP_ADAPTER_UNICAST_ADDRESS_DEFINE(suffix, addition) \
- typedef struct _IP_ADAPTER_UNICAST_ADDRESS ## suffix { \
- _IP_ADAPTER_UNICAST_ADDRESS_HEAD \
- struct _IP_ADAPTER_UNICAST_ADDRESS ## suffix *Next; \
- _IP_ADAPTER_UNICAST_ADDRESS_BASE \
- addition \
- } IP_ADAPTER_UNICAST_ADDRESS ## suffix, *PIP_ADAPTER_UNICAST_ADDRESS ## suffix;
-
-/* _IP_ADAPTER_UNICAST_ADDRESS_DEFINE(,) defined in w32api headers */
-_IP_ADAPTER_UNICAST_ADDRESS_DEFINE(_VISTA, _IP_ADAPTER_UNICAST_ADDRESS_ADD_VISTA)
-
-
-#ifndef __MINGW64_VERSION_MAJOR
-typedef struct _IP_ADAPTER_WINS_SERVER_ADDRESS {
- union {
- ULONGLONG Alignment;
- struct {
- ULONG Length;
- DWORD Reserved;
- };
- };
- struct _IP_ADAPTER_WINS_SERVER_ADDRESS *Next;
- SOCKET_ADDRESS Address;
-} IP_ADAPTER_WINS_SERVER_ADDRESS, *PIP_ADAPTER_WINS_SERVER_ADDRESS, *PIP_ADAPTER_WINS_SERVER_ADDRESS_LH;
-
-typedef struct _IP_ADAPTER_GATEWAY_ADDRESS {
- union {
- ULONGLONG Alignment;
- struct {
- ULONG Length;
- DWORD Reserved;
- };
- };
- struct _IP_ADAPTER_GATEWAY_ADDRESS *Next;
- SOCKET_ADDRESS Address;
-} IP_ADAPTER_GATEWAY_ADDRESS, *PIP_ADAPTER_GATEWAY_ADDRESS, *PIP_ADAPTER_GATEWAY_ADDRESS_LH;
-#endif
-
-typedef UINT32 NET_IF_COMPARTMENT_ID;
-typedef GUID NET_IF_NETWORK_GUID;
-
-#ifndef __MINGW64_VERSION_MAJOR
-typedef enum _NET_IF_CONNECTION_TYPE {
- NET_IF_CONNECTION_DEDICATED = 1,
- NET_IF_CONNECTION_PASSIVE,
- NET_IF_CONNECTION_DEMAND,
- NET_IF_CONNECTION_MAXIMUM
-} NET_IF_CONNECTION_TYPE, *PNET_IF_CONNECTION_TYPE;
-
-typedef enum {
- TUNNEL_TYPE_NONE = 0,
- TUNNEL_TYPE_OTHER,
- TUNNEL_TYPE_DIRECT,
- TUNNEL_TYPE_6TO4,
- TUNNEL_TYPE_ISATAP,
- TUNNEL_TYPE_TEREDO,
- TUNNEL_TYPE_IPHTTPS
-} TUNNEL_TYPE, *PTUNNEL_TYPE;
-#endif
-
-/*
- A DUID consists of a two-octet type code represented in network byte
- order, followed by a variable number of octets that make up the
- actual identifier. A DUID can be no more than 128 octets long (not
- including the type code).
- */
-#define MAX_DHCPV6_DUID_LENGTH 130
-
-#ifndef __MINGW64_VERSION_MAJOR
-typedef union _NET_LUID {
- ULONG64 Value;
- struct {
- ULONG64 Reserved : 24;
- ULONG64 NetLuidIndex : 24;
- ULONG64 IfType : 16;
- } Info;
-} NET_LUID, *PNET_LUID, IF_LUID;
-
-#define MAX_DNS_SUFFIX_STRING_LENGTH 246
-
-typedef struct _IP_ADAPTER_DNS_SUFFIX {
- struct _IP_ADAPTER_DNS_SUFFIX *Next;
- WCHAR String[MAX_DNS_SUFFIX_STRING_LENGTH];
-} IP_ADAPTER_DNS_SUFFIX, *PIP_ADAPTER_DNS_SUFFIX;
-#endif
-
-
-
-#define _IP_ADAPTER_ADDRESSES_HEAD \
- union { \
- ULONGLONG Alignment; \
- struct { \
- ULONG Length; \
- DWORD IfIndex; \
- }; \
- };
-
-#define _IP_ADAPTER_ADDRESSES_BASE \
- PCHAR AdapterName; \
- PIP_ADAPTER_UNICAST_ADDRESS FirstUnicastAddress; \
- PIP_ADAPTER_ANYCAST_ADDRESS FirstAnycastAddress; \
- PIP_ADAPTER_MULTICAST_ADDRESS FirstMulticastAddress; \
- PIP_ADAPTER_DNS_SERVER_ADDRESS FirstDnsServerAddress; \
- PWCHAR DnsSuffix; \
- PWCHAR Description; \
- PWCHAR FriendlyName; \
- BYTE PhysicalAddress[MAX_ADAPTER_ADDRESS_LENGTH]; \
- DWORD PhysicalAddressLength; \
- DWORD Flags; \
- DWORD Mtu; \
- DWORD IfType; \
- IF_OPER_STATUS OperStatus;
-
-#define _IP_ADAPTER_ADDRESSES_ADD_XPSP1 \
- DWORD Ipv6IfIndex; \
- DWORD ZoneIndices[16]; \
- PIP_ADAPTER_PREFIX FirstPrefix; \
-
-
-#define _IP_ADAPTER_ADDRESSES_ADD_VISTA \
- _IP_ADAPTER_ADDRESSES_ADD_XPSP1 \
- ULONG64 TransmitLinkSpeed; \
- ULONG64 ReceiveLinkSpeed; \
- PIP_ADAPTER_WINS_SERVER_ADDRESS_LH FirstWinsServerAddress; \
- PIP_ADAPTER_GATEWAY_ADDRESS_LH FirstGatewayAddress; \
- ULONG Ipv4Metric; \
- ULONG Ipv6Metric; \
- IF_LUID Luid; \
- SOCKET_ADDRESS Dhcpv4Server; \
- NET_IF_COMPARTMENT_ID CompartmentId; \
- NET_IF_NETWORK_GUID NetworkGuid; \
- NET_IF_CONNECTION_TYPE ConnectionType; \
- TUNNEL_TYPE TunnelType; \
- SOCKET_ADDRESS Dhcpv6Server; \
- BYTE Dhcpv6ClientDuid[MAX_DHCPV6_DUID_LENGTH]; \
- ULONG Dhcpv6ClientDuidLength; \
- ULONG Dhcpv6Iaid;
-
-#define _IP_ADAPTER_ADDRESSES_ADD_2008_OR_VISTASP1 \
- _IP_ADAPTER_ADDRESSES_ADD_VISTA \
- PIP_ADAPTER_DNS_SUFFIX FirstDnsSuffix;
-
-#define _IP_ADAPTER_ADDRESSES_DEFINE(suffix, addition) \
- typedef struct _IP_ADAPTER_ADDRESSES ## suffix { \
- _IP_ADAPTER_ADDRESSES_HEAD \
- struct _IP_ADAPTER_ADDRESSES ## suffix *Next; \
- _IP_ADAPTER_ADDRESSES_BASE \
- addition \
- } IP_ADAPTER_ADDRESSES ## suffix, *PIP_ADAPTER_ADDRESSES ## suffix;
-
-
-/* _IP_ADAPTER_ADDRESSES_DEFINE(,) defined in w32api headers */
-_IP_ADAPTER_ADDRESSES_DEFINE(_XPSP1, _IP_ADAPTER_ADDRESSES_ADD_XPSP1)
-_IP_ADAPTER_ADDRESSES_DEFINE(_VISTA, _IP_ADAPTER_ADDRESSES_ADD_VISTA)
-_IP_ADAPTER_ADDRESSES_DEFINE(_2008_OR_VISTASP1, _IP_ADAPTER_ADDRESSES_ADD_2008_OR_VISTASP1)
-
-static int
-EnumNICs_IPv6_get_ifs_count(_win_socket s)
-{
- DWORD dwret = 0, err;
- int iret;
-
- iret = WSAIoctl(s, SIO_ADDRESS_LIST_QUERY, NULL, 0, NULL, 0,
- &dwret, NULL, NULL);
- err = GetLastError();
- if (iret == SOCKET_ERROR && err == WSAEFAULT)
- return dwret;
- else if (iret == 0)
- return 0;
- return GNUNET_SYSERR;
-}
-
-static int
-EnumNICs_IPv6_get_ifs(_win_socket s, SOCKET_ADDRESS_LIST *inf, int size)
-{
- int iret;
- DWORD dwret = 0;
-
- iret = WSAIoctl(s, SIO_ADDRESS_LIST_QUERY, NULL, 0, inf, size,
- &dwret, NULL, NULL);
-
- if (iret != 0 || dwret != size)
- {
- /* It's supposed to succeed! And size should be the same */
- return GNUNET_SYSERR;
- }
- return GNUNET_OK;
-}
-
-#undef GNUNET_malloc
-#define GNUNET_malloc(a) HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY | \
- HEAP_GENERATE_EXCEPTIONS, a)
-
-#undef GNUNET_free
-#define GNUNET_free(a) HeapFree(GetProcessHeap(), 0, a)
-
-#undef GNUNET_free_non_null
-#define GNUNET_free_non_null(a) do { if ((a) != NULL) GNUNET_free (a); } while (0)
-
-static int
-EnumNICs_IPv4_get_ifs(SOCKET s, INTERFACE_INFO **inf, int *size)
-{
- int iret;
- DWORD dwret = 0;
- DWORD error;
- INTERFACE_INFO *ii = NULL;
- DWORD ii_size = sizeof(INTERFACE_INFO) * 15;
-
- while (TRUE)
- {
- if (ii_size >= sizeof(INTERFACE_INFO) * 1000)
- return GNUNET_SYSERR;
- ii = (INTERFACE_INFO *)GNUNET_malloc(ii_size);
- dwret = 0;
- iret = WSAIoctl(s, SIO_GET_INTERFACE_LIST, NULL, 0, ii, ii_size,
- &dwret, NULL, NULL);
- error = GetLastError();
- if (iret == SOCKET_ERROR)
- {
- if (error == WSAEFAULT)
- {
- GNUNET_free(ii);
- ii_size *= 2;
- continue;
- }
- GNUNET_free(ii);
- return GNUNET_SYSERR;
- }
- else
- {
- *inf = ii;
- *size = dwret;
- return GNUNET_OK;
- }
- }
- return GNUNET_SYSERR;
-}
-
-int
-EnumNICs2(INTERFACE_INFO **ifs4, int *ifs4_len, SOCKET_ADDRESS_LIST **ifs6)
-{
- int result = 0;
- _win_socket s4;
- _win_socket s6;
- int ifs4len = 0;
- int ifs6len = 0;
- INTERFACE_INFO *interfaces4 = NULL;
- SOCKET_ADDRESS_LIST *interfaces6 = NULL;
-
- SetLastError(0);
- s4 = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
- (void)GetLastError();
- SetLastError(0);
- s6 = socket(AF_INET6, SOCK_STREAM, IPPROTO_TCP);
- (void)GetLastError();
- if (s6 != INVALID_SOCKET)
- {
- ifs6len = EnumNICs_IPv6_get_ifs_count(s6);
- if (ifs6len > 0)
- {
- interfaces6 = (SOCKET_ADDRESS_LIST *)GNUNET_malloc(ifs6len);
- result = EnumNICs_IPv6_get_ifs(s6, interfaces6, ifs6len) || result;
- }
- closesocket(s6);
- s6 = INVALID_SOCKET;
- }
-
- if (s4 != INVALID_SOCKET)
- {
- result = EnumNICs_IPv4_get_ifs(s4, &interfaces4, &ifs4len) || result;
- closesocket(s4);
- s4 = INVALID_SOCKET;
- }
- if (ifs6len + ifs4len == 0)
- goto error;
-
- if (!result)
- {
- *ifs4 = interfaces4;
- *ifs4_len = ifs4len;
- *ifs6 = interfaces6;
- return GNUNET_OK;
- }
-error:
- if (interfaces4 != NULL)
- GNUNET_free(interfaces4);
- if (interfaces6 != NULL)
- GNUNET_free(interfaces6);
- if (s4 != INVALID_SOCKET)
- closesocket(s4);
- if (s6 != INVALID_SOCKET)
- closesocket(s6);
- return GNUNET_SYSERR;
-}
-
-
-/**
- * @returns #GNUNET_OK on success, #GNUNET_SYSERR on error
- */
-int
-EnumNICs3(struct EnumNICs3_results **results, int *results_count)
-{
- DWORD dwRetVal = 0;
- int count = 0;
- ULONG flags = /*GAA_FLAG_INCLUDE_PREFIX |*/ GAA_FLAG_SKIP_ANYCAST |
- GAA_FLAG_SKIP_MULTICAST | GAA_FLAG_SKIP_DNS_SERVER;
- struct sockaddr_in6 examplecom6;
- IPAddr examplecom;
- DWORD best_interface = 0;
- DWORD best_interface6 = 0;
-
- int use_enum2 = 0;
- INTERFACE_INFO *interfaces4 = NULL;
- int interfaces4_len = 0;
- SOCKET_ADDRESS_LIST *interfaces6 = NULL;
-
- unsigned long outBufLen = sizeof(IP_ADAPTER_ADDRESSES);
- IP_ADAPTER_ADDRESSES *pCurrentAddress = NULL;
- IP_ADAPTER_ADDRESSES *pAddresses = (IP_ADAPTER_ADDRESSES *)GNUNET_malloc(outBufLen);
-
- if (GetAdaptersAddresses(AF_UNSPEC, flags, NULL, pAddresses, &outBufLen)
- == ERROR_BUFFER_OVERFLOW)
- {
- GNUNET_free(pAddresses);
- pAddresses = (IP_ADAPTER_ADDRESSES *)GNUNET_malloc(outBufLen);
- }
-
- dwRetVal = GetAdaptersAddresses(AF_UNSPEC, flags, NULL, pAddresses, &outBufLen);
-
- if (dwRetVal != NO_ERROR)
- {
- GNUNET_free(pAddresses);
- return GNUNET_SYSERR;
- }
-
- if (pAddresses->Length < sizeof(IP_ADAPTER_ADDRESSES_VISTA))
- {
- use_enum2 = 1;
-
- /* Enumerate NICs using WSAIoctl() */
- if (GNUNET_OK != EnumNICs2(&interfaces4, &interfaces4_len, &interfaces6))
- {
- GNUNET_free(pAddresses);
- return GNUNET_SYSERR;
- }
- }
-
- examplecom = inet_addr("192.0.34.166"); /* www.example.com */
- if (GetBestInterface(examplecom, &best_interface) != NO_ERROR)
- best_interface = 0;
-
- if (GNGetBestInterfaceEx != NULL)
- {
- examplecom6.sin6_family = AF_INET6;
- examplecom6.sin6_port = 0;
- examplecom6.sin6_flowinfo = 0;
- examplecom6.sin6_scope_id = 0;
- inet_pton(AF_INET6, "2001:500:88:200:0:0:0:10",
- (struct sockaddr *)&examplecom6.sin6_addr);
- dwRetVal = GNGetBestInterfaceEx((struct sockaddr *)&examplecom6,
- &best_interface6);
- if (dwRetVal != NO_ERROR)
- best_interface6 = 0;
- }
-
- /* Give IPv6 a priority */
- if (best_interface6 != 0)
- best_interface = best_interface6;
-
- count = 0;
- for (pCurrentAddress = pAddresses;
- pCurrentAddress != NULL; pCurrentAddress = pCurrentAddress->Next)
- {
- if (pCurrentAddress->OperStatus == IfOperStatusUp)
- {
- IP_ADAPTER_UNICAST_ADDRESS *unicast = NULL;
- for (unicast = pCurrentAddress->FirstUnicastAddress; unicast != NULL;
- unicast = unicast->Next)
- {
- if ((unicast->Address.lpSockaddr->sa_family == AF_INET ||
- unicast->Address.lpSockaddr->sa_family == AF_INET6) &&
- (unicast->DadState == IpDadStateDeprecated ||
- unicast->DadState == IpDadStatePreferred))
- count += 1;
- }
- }
- }
-
- if (count == 0)
- {
- *results = NULL;
- *results_count = 0;
- GNUNET_free(pAddresses);
- GNUNET_free_non_null(interfaces4);
- GNUNET_free_non_null(interfaces6);
- return GNUNET_OK;
- }
-
- *results = (struct EnumNICs3_results *)GNUNET_malloc(
- sizeof(struct EnumNICs3_results) * count);
- *results_count = count;
-
- count = 0;
- for (pCurrentAddress = pAddresses;
- pCurrentAddress != NULL; pCurrentAddress = pCurrentAddress->Next)
- {
- struct EnumNICs3_results *r;
- IP_ADAPTER_UNICAST_ADDRESS *unicast = NULL;
- if (pCurrentAddress->OperStatus != IfOperStatusUp)
- continue;
- for (unicast = pCurrentAddress->FirstUnicastAddress; unicast != NULL;
- unicast = unicast->Next)
- {
- int i, j;
- int mask_length = -1;
- char dst[INET6_ADDRSTRLEN + 1];
-
- if ((unicast->Address.lpSockaddr->sa_family != AF_INET &&
- unicast->Address.lpSockaddr->sa_family != AF_INET6) ||
- (unicast->DadState != IpDadStateDeprecated &&
- unicast->DadState != IpDadStatePreferred))
- continue;
-
- r = &(*results)[count];
- r->flags = 0;
- if (pCurrentAddress->IfIndex > 0 &&
- pCurrentAddress->IfIndex == best_interface &&
- unicast->Address.lpSockaddr->sa_family == AF_INET)
- r->is_default = 1;
- else if (pCurrentAddress->Ipv6IfIndex > 0 &&
- pCurrentAddress->Ipv6IfIndex == best_interface6 &&
- unicast->Address.lpSockaddr->sa_family == AF_INET6)
- r->is_default = 1;
- else
- r->is_default = 0;
-
- /* Don't choose default interface twice */
- if (r->is_default)
- best_interface = best_interface6 = 0;
-
- if (!use_enum2)
- {
- GNUNET_memcpy(&r->address, unicast->Address.lpSockaddr,
- unicast->Address.iSockaddrLength);
- memset(&r->mask, 0, sizeof(struct sockaddr));
- mask_length = ((IP_ADAPTER_UNICAST_ADDRESS_VISTA *)unicast)->
- OnLinkPrefixLength;
- /* OnLinkPrefixLength is the number of leading 1s in the mask.
- * OnLinkPrefixLength is available on Vista and later (hence use_enum2).
- */
- if (unicast->Address.lpSockaddr->sa_family == AF_INET)
- {
- struct sockaddr_in *m = (struct sockaddr_in *)&r->mask;
- for (i = 0; i < mask_length; i++)
- ((unsigned char *)&m->sin_addr)[i / 8] |= 0x80 >> (i % 8);
- }
- else if (unicast->Address.lpSockaddr->sa_family == AF_INET6)
- {
- struct sockaddr_in6 *m = (struct sockaddr_in6 *)&r->mask;
- struct sockaddr_in6 *b = (struct sockaddr_in6 *)&r->broadcast;
- for (i = 0; i < mask_length; i++)
- ((unsigned char *)&m->sin6_addr)[i / 8] |= 0x80 >> (i % 8);
- GNUNET_memcpy(&r->broadcast, &r->address, unicast->Address.iSockaddrLength);
- for (i = mask_length; i < 128; i++)
- ((unsigned char *)&b->sin6_addr)[i / 8] |= 0x80 >> (i % 8);
- }
- r->flags |= ENUMNICS3_MASK_OK;
- }
- else
- {
- int found = 0;
- if (unicast->Address.lpSockaddr->sa_family == AF_INET)
- {
- for (i = 0; !found && i < interfaces4_len / sizeof(INTERFACE_INFO); i++)
- {
- struct sockaddr_in *m = (struct sockaddr_in *)&r->mask;
- GNUNET_memcpy(&interfaces4[i].iiAddress.Address,
- unicast->Address.lpSockaddr,
- unicast->Address.iSockaddrLength);
- found = 1;
- GNUNET_memcpy(&r->address, &interfaces4[i].iiAddress.Address,
- sizeof(struct sockaddr_in));
- GNUNET_memcpy(&r->mask, &interfaces4[i].iiNetmask.Address,
- sizeof(struct sockaddr_in));
- for (mask_length = 0;
- ((unsigned char *)&m->sin_addr)[mask_length / 8] &
- 0x80 >> (mask_length % 8); mask_length++)
- {
- }
- r->flags |= ENUMNICS3_MASK_OK;
- }
- }
- else if (unicast->Address.lpSockaddr->sa_family == AF_INET6)
- {
- for (i = 0;
- interfaces6 != NULL && !found && i < interfaces6->iAddressCount;
- i++)
- {
- GNUNET_memcpy(interfaces6->Address[i].lpSockaddr,
- unicast->Address.lpSockaddr,
- unicast->Address.iSockaddrLength);
- found = 1;
- GNUNET_memcpy(&r->address, interfaces6->Address[i].lpSockaddr,
- sizeof(struct sockaddr_in6));
- /* TODO: Find a way to reliably get network mask for IPv6 on XP */
- memset(&r->mask, 0, sizeof(struct sockaddr));
- r->flags &= ~ENUMNICS3_MASK_OK;
- }
- }
- if (!found)
- {
- DebugBreak();
- }
- }
- if (unicast->Address.lpSockaddr->sa_family == AF_INET)
- {
- struct sockaddr_in *m = (struct sockaddr_in *)&r->mask;
- struct sockaddr_in *a = (struct sockaddr_in *)&r->address;
- /* copy address to broadcast, then flip all the trailing bits not
- * falling under netmask to 1,
- * so we get, 192.168.0.255 from, say, 192.168.0.43 with mask == 24.
- */
- GNUNET_memcpy(&r->broadcast, &r->address, unicast->Address.iSockaddrLength);
- for (i = mask_length; i < 32; i++)
- ((unsigned char *)&m->sin_addr)[i / 8] |= 0x80 >> (i % 8);
- r->flags |= ENUMNICS3_BCAST_OK;
- r->addr_size = sizeof(struct sockaddr_in);
- inet_ntop(AF_INET, &a->sin_addr, dst, INET_ADDRSTRLEN);
- }
- else if (unicast->Address.lpSockaddr->sa_family == AF_INET6)
- {
- struct sockaddr_in6 *a = (struct sockaddr_in6 *)&r->address;
- /* for IPv6 broadcast is not defined, zero it down */
- memset(&r->broadcast, 0, sizeof(struct sockaddr));
- r->flags &= ~ENUMNICS3_BCAST_OK;
- r->addr_size = sizeof(struct sockaddr_in6);
- inet_ntop(AF_INET6, &a->sin6_addr, dst, INET6_ADDRSTRLEN);
- }
-
- i = 0;
- i += snprintf(&r->pretty_name[i], 1000 - i > 0 ? 1000 - i : 0,
- "%S (%s", pCurrentAddress->FriendlyName, dst);
- for (j = 0; j < pCurrentAddress->PhysicalAddressLength; j++)
- i += snprintf(&r->pretty_name[i], 1000 - i > 0 ? 1000 - i : 0,
- "%s%02X", j > 0 ? ":" : " - ", pCurrentAddress->PhysicalAddress[j]);
- i += snprintf(&r->pretty_name[i], 1000 - i > 0 ? 1000 - i : 0, ")");
- r->pretty_name[1000] = '\0';
- count += 1;
- }
- }
-
- if (use_enum2)
- {
- GNUNET_free_non_null(interfaces4);
- GNUNET_free_non_null(interfaces6);
- }
-
- GNUNET_free(pAddresses);
- return GNUNET_OK;
-}
-
-void
-EnumNICs3_free(struct EnumNICs3_results *r)
-{
- GNUNET_free_non_null(r);
-}
-
-
-/**
- * Lists all network interfaces in a combo box
- * Used by the basic GTK configurator
- *
- * @param callback function to call for each NIC
- * @param callback_cls closure for callback
- */
-int
-ListNICs(void (*callback)(void *, const char *, int), void * callback_cls)
-{
- int r;
- int i;
- struct EnumNICs3_results *results = NULL;
- int results_count;
-
- r = EnumNICs3(&results, &results_count);
- if (r != GNUNET_OK)
- return GNUNET_NO;
-
- for (i = 0; i < results_count; i++)
- callback(callback_cls, results[i].pretty_name, results[i].is_default);
- GNUNET_free_non_null(results);
- return GNUNET_YES;
-}
-
-/**
- * @brief Installs the Windows service
- * @param servicename name of the service as diplayed by the SCM
- * @param application path to the application binary
- * @param username the name of the service's user account
- * @returns 0 on success
- * 1 if the Windows version doesn't support services
- * 2 if the SCM could not be opened
- * 3 if the service could not be created
- */
-int InstallAsService(char *servicename, char *application, char *username)
-{
- SC_HANDLE hManager, hService;
- char szEXE[_MAX_PATH + 17] = "\"";
- char *user = NULL;
-
- if (!GNOpenSCManager)
- return 1;
-
- plibc_conv_to_win_path(application, szEXE + 1);
- strcat(szEXE, "\" --win-service");
- hManager = GNOpenSCManager(NULL, NULL, SC_MANAGER_CREATE_SERVICE);
- if (!hManager)
- return 2;
-
- if (username)
- {
- user = (char *)malloc(strlen(username) + 3);
- sprintf(user, ".\\%s", username);
- }
-
- hService = GNCreateService(hManager, (LPCTSTR)servicename, (LPCTSTR)servicename, 0,
- SERVICE_WIN32_OWN_PROCESS, SERVICE_AUTO_START, SERVICE_ERROR_NORMAL, (LPCTSTR)szEXE,
- NULL, NULL, NULL, (LPCTSTR)user, (LPCTSTR)username);
-
- if (user)
- free(user);
-
- if (!hService)
- return 3;
-
- GNCloseServiceHandle(hService);
-
- return 0;
-}
-
-
-/**
- * @brief Uninstall Windows service
- * @param servicename name of the service to delete
- * @returns 0 on success
- * 1 if the Windows version doesn't support services
- * 2 if the SCM could not be openend
- * 3 if the service cannot be accessed
- * 4 if the service cannot be deleted
- */
-int
-UninstallService(char *servicename)
-{
- SC_HANDLE hManager, hService;
-
- if (!GNOpenSCManager)
- return 1;
-
- hManager = GNOpenSCManager(NULL, NULL, SC_MANAGER_CONNECT);
- if (!hManager)
- return 2;
-
- if (!(hService = GNOpenService(hManager, (LPCTSTR)servicename, DELETE)))
- {
- if (GetLastError() != ERROR_SERVICE_DOES_NOT_EXIST)
- return 3;
- else
- goto closeSCM;
- }
-
- if (!GNDeleteService(hService))
- if (GetLastError() != ERROR_SERVICE_MARKED_FOR_DELETE)
- return 4;
-
-closeSCM:
- GNCloseServiceHandle(hService);
-
- return 0;
-}
-
-/**
- * @author Scott Field, Microsoft
- * @see http://support.microsoft.com/?scid=kb;en-us;132958
- * @date 12-Jul-95
- */
-void
-_InitLsaString(PLSA_UNICODE_STRING LsaString, LPWSTR String)
-{
- DWORD StringLength;
-
- if (String == NULL)
- {
- LsaString->Buffer = NULL;
- LsaString->Length = 0;
- LsaString->MaximumLength = 0;
- return;
- }
-
- StringLength = wcslen(String);
- LsaString->Buffer = String;
- LsaString->Length = (USHORT)StringLength * sizeof(WCHAR);
- LsaString->MaximumLength = (USHORT)(StringLength + 1) * sizeof(WCHAR);
-}
-
-
-/**
- * @author Scott Field, Microsoft
- * @see http://support.microsoft.com/?scid=kb;en-us;132958
- * @date 12-Jul-95
- */
-NTSTATUS
-_OpenPolicy(LPWSTR ServerName, DWORD DesiredAccess, PLSA_HANDLE PolicyHandle)
-{
- LSA_OBJECT_ATTRIBUTES ObjectAttributes;
- LSA_UNICODE_STRING ServerString;
- PLSA_UNICODE_STRING Server = NULL;
-
- /* Always initialize the object attributes to all zeroes. */
- ZeroMemory(&ObjectAttributes, sizeof(ObjectAttributes));
-
- if (ServerName != NULL)
- {
- /* Make a LSA_UNICODE_STRING out of the LPWSTR passed in */
- _InitLsaString(&ServerString, ServerName);
- Server = &ServerString;
- }
-
- /* Attempt to open the policy. */
- return GNLsaOpenPolicy(Server,
- &ObjectAttributes, DesiredAccess, PolicyHandle);
-}
-
-/**
- * @brief Obtain a SID representing the supplied account on the supplied system
- * @return TRUE on success, FALSE on failure
- * @author Scott Field, Microsoft
- * @date 12-Jul-95
- * @remarks A buffer is allocated which contains the SID representing the
- * supplied account. This buffer should be freed when it is no longer
- * needed by calling\n
- * HeapFree(GetProcessHeap(), 0, buffer)
- * @remarks Call GetLastError() to obtain extended error information.
- * @see http://support.microsoft.com/?scid=kb;en-us;132958
- */
-BOOL
-_GetAccountSid(LPCTSTR SystemName, LPCTSTR AccountName, PSID * Sid)
-{
- LPTSTR ReferencedDomain = NULL;
- DWORD cbSid = 128; /* initial allocation attempt */
- DWORD cchReferencedDomain = 16; /* initial allocation size */
- SID_NAME_USE peUse;
- BOOL bSuccess = FALSE; /* assume this function will fail */
-
- /* initial memory allocations */
- if ((*Sid = HeapAlloc(GetProcessHeap(), 0, cbSid)) == NULL)
- return FALSE;
-
- if ((ReferencedDomain = (LPTSTR)HeapAlloc(GetProcessHeap(),
- 0,
- cchReferencedDomain *
- sizeof(TCHAR))) == NULL)
- return FALSE;
-
- /* Obtain the SID of the specified account on the specified system. */
- while (!GNLookupAccountName(SystemName, /* machine to lookup account on */
- AccountName, /* account to lookup */
- *Sid, /* SID of interest */
- &cbSid, /* size of SID */
- ReferencedDomain, /* domain account was found on */
- &cchReferencedDomain, &peUse))
- {
- if (GetLastError() == ERROR_INSUFFICIENT_BUFFER)
- {
- /* reallocate memory */
- if ((*Sid = HeapReAlloc(GetProcessHeap(), 0, *Sid, cbSid)) == NULL)
- return FALSE;
-
- if ((ReferencedDomain = (LPTSTR)HeapReAlloc(GetProcessHeap(),
- 0,
- ReferencedDomain,
- cchReferencedDomain
- * sizeof(TCHAR))) == NULL)
- return FALSE;
- }
- else
- goto end;
- }
-
- /* Indicate success. */
- bSuccess = TRUE;
-
-end:
- /* Cleanup and indicate failure, if appropriate. */
- HeapFree(GetProcessHeap(), 0, ReferencedDomain);
-
- if (!bSuccess)
- {
- if (*Sid != NULL)
- {
- HeapFree(GetProcessHeap(), 0, *Sid);
- *Sid = NULL;
- }
- }
-
- return bSuccess;
-}
-
-/**
- * @author Scott Field, Microsoft
- * @see http://support.microsoft.com/?scid=kb;en-us;132958
- * @date 12-Jul-95
- */
-NTSTATUS
-_SetPrivilegeOnAccount(LSA_HANDLE PolicyHandle,/* open policy handle */
- PSID AccountSid, /* SID to grant privilege to */
- LPWSTR PrivilegeName, /* privilege to grant (Unicode) */
- BOOL bEnable /* enable or disable */
- )
-{
- LSA_UNICODE_STRING PrivilegeString;
-
- /* Create a LSA_UNICODE_STRING for the privilege name. */
- _InitLsaString(&PrivilegeString, PrivilegeName);
-
- /* grant or revoke the privilege, accordingly */
- if (bEnable)
- {
- NTSTATUS i;
-
- i = GNLsaAddAccountRights(PolicyHandle, /* open policy handle */
- AccountSid, /* target SID */
- &PrivilegeString, /* privileges */
- 1 /* privilege count */
- );
- return i;
- }
- else
- {
- return GNLsaRemoveAccountRights(PolicyHandle, /* open policy handle */
- AccountSid, /* target SID */
- FALSE, /* do not disable all rights */
- &PrivilegeString, /* privileges */
- 1 /* privilege count */
- );
- }
-}
-
-/**
- * @brief Create a Windows service account
- * @return 0 on success, > 0 otherwise
- * @param pszName the name of the account
- * @param pszDesc description of the account
- */
-int
-CreateServiceAccount(const char *pszName,
- const char *pszDesc)
-{
- USER_INFO_1 ui;
- USER_INFO_1008 ui2;
- NET_API_STATUS nStatus;
- wchar_t wszName[MAX_NAME_LENGTH], wszDesc[MAX_NAME_LENGTH];
- LSA_HANDLE hPolicy;
- PSID pSID;
-
- if (!GNNetUserAdd)
- return 1;
- mbstowcs(wszName, pszName, strlen(pszName) + 1);
- mbstowcs(wszDesc, pszDesc, strlen(pszDesc) + 1);
-
- memset(&ui, 0, sizeof(ui));
- ui.usri1_name = wszName;
- ui.usri1_password = wszName; /* account is locked anyway */
- ui.usri1_priv = USER_PRIV_USER;
- ui.usri1_comment = wszDesc;
- ui.usri1_flags = UF_SCRIPT;
-
- nStatus = GNNetUserAdd(NULL, 1, (LPBYTE)&ui, NULL);
-
- if (nStatus != NERR_Success && nStatus != NERR_UserExists)
- return 2;
-
- ui2.usri1008_flags = UF_PASSWD_CANT_CHANGE | UF_DONT_EXPIRE_PASSWD;
- GNNetUserSetInfo(NULL, wszName, 1008, (LPBYTE)&ui2, NULL);
-
- if (!NT_SUCCESS(_OpenPolicy(NULL, POLICY_ALL_ACCESS, &hPolicy)))
- return 3;
-
- _GetAccountSid(NULL, (LPCTSTR)pszName, &pSID);
-
- if (!NT_SUCCESS(_SetPrivilegeOnAccount(hPolicy, pSID, (LPWSTR)L"SeServiceLogonRight", TRUE)))
- return 4;
-
- _SetPrivilegeOnAccount(hPolicy, pSID, (LPWSTR)L"SeDenyInteractiveLogonRight", TRUE);
- _SetPrivilegeOnAccount(hPolicy, pSID, (LPWSTR)L"SeDenyBatchLogonRight", TRUE);
- _SetPrivilegeOnAccount(hPolicy, pSID, (LPWSTR)L"SeDenyNetworkLogonRight", TRUE);
-
- GNLsaClose(hPolicy);
-
- return 0;
-}
-
-/**
- * @brief Grant permission to a file
- * @param lpszFileName the name of the file or directory
- * @param lpszAccountName the user account
- * @param dwAccessMask the desired access (e.g. GENERIC_ALL)
- * @return TRUE on success
- * @remark based on http://support.microsoft.com/default.aspx?scid=KB;EN-US;Q102102&
- */
-BOOL AddPathAccessRights(char *lpszFileName, char *lpszAccountName,
- DWORD dwAccessMask)
-{
- /* SID variables. */
- SID_NAME_USE snuType;
- TCHAR * szDomain = NULL;
- DWORD cbDomain = 0;
- LPVOID pUserSID = NULL;
- DWORD cbUserSID = 0;
-
- /* File SD variables. */
- PSECURITY_DESCRIPTOR pFileSD = NULL;
- DWORD cbFileSD = 0;
-
- /* New SD variables. */
- SECURITY_DESCRIPTOR newSD;
-
- /* ACL variables. */
- PACL pACL = NULL;
- BOOL fDaclPresent;
- BOOL fDaclDefaulted;
- ACL_SIZE_INFORMATION AclInfo;
-
- /* New ACL variables. */
- PACL pNewACL = NULL;
- DWORD cbNewACL = 0;
-
- /* Temporary ACE. */
- LPVOID pTempAce = NULL;
- UINT CurrentAceIndex = 0;
-
- UINT newAceIndex = 0;
-
- /* Assume function will fail. */
- BOOL fResult = FALSE;
- BOOL fAPISuccess;
-
- SECURITY_INFORMATION secInfo = DACL_SECURITY_INFORMATION;
-
- /**
- * STEP 1: Get SID of the account name specified.
- */
- fAPISuccess = GNLookupAccountName(NULL, (LPCTSTR)lpszAccountName,
- pUserSID, &cbUserSID, (LPTSTR)szDomain, &cbDomain, &snuType);
-
- /* API should have failed with insufficient buffer. */
- if (fAPISuccess)
- goto end;
- else if (GetLastError() != ERROR_INSUFFICIENT_BUFFER)
- {
- goto end;
- }
-
- pUserSID = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, cbUserSID);
- if (!pUserSID)
- {
- goto end;
- }
-
- szDomain = (TCHAR *)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, cbDomain * sizeof(TCHAR));
- if (!szDomain)
- {
- goto end;
- }
-
- fAPISuccess = GNLookupAccountName(NULL, (LPCTSTR)lpszAccountName,
- pUserSID, &cbUserSID, (LPTSTR)szDomain, &cbDomain, &snuType);
- if (!fAPISuccess)
- {
- goto end;
- }
-
- /**
- * STEP 2: Get security descriptor (SD) of the file specified.
- */
- fAPISuccess = GNGetFileSecurity((LPCTSTR)lpszFileName,
- secInfo, pFileSD, 0, &cbFileSD);
-
- /* API should have failed with insufficient buffer. */
- if (fAPISuccess)
- goto end;
- else if (GetLastError() != ERROR_INSUFFICIENT_BUFFER)
- {
- goto end;
- }
-
- pFileSD = (PSECURITY_DESCRIPTOR)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
- cbFileSD);
- if (!pFileSD)
- {
- goto end;
- }
-
- fAPISuccess = GNGetFileSecurity((LPCTSTR)lpszFileName,
- secInfo, pFileSD, cbFileSD, &cbFileSD);
- if (!fAPISuccess)
- {
- goto end;
- }
-
- /**
- * STEP 3: Initialize new SD.
- */
- if (!GNInitializeSecurityDescriptor(&newSD,
- SECURITY_DESCRIPTOR_REVISION))
- {
- goto end;
- }
-
- /**
- * STEP 4: Get DACL from the old SD.
- */
- if (!GNGetSecurityDescriptorDacl(pFileSD, &fDaclPresent, &pACL,
- &fDaclDefaulted))
- {
- goto end;
- }
-
- /**
- * STEP 5: Get size information for DACL.
- */
- AclInfo.AceCount = 0; // Assume NULL DACL.
- AclInfo.AclBytesFree = 0;
- AclInfo.AclBytesInUse = sizeof(ACL);
-
- if (pACL == NULL)
- fDaclPresent = FALSE;
-
- /* If not NULL DACL, gather size information from DACL. */
- if (fDaclPresent)
- {
- if (!GNGetAclInformation(pACL, &AclInfo,
- sizeof(ACL_SIZE_INFORMATION), AclSizeInformation))
- {
- goto end;
- }
- }
-
- /**
- * STEP 6: Compute size needed for the new ACL.
- */
- cbNewACL = AclInfo.AclBytesInUse + sizeof(ACCESS_ALLOWED_ACE)
- + GetLengthSid(pUserSID) - sizeof(DWORD);
-
- /**
- * STEP 7: Allocate memory for new ACL.
- */
- pNewACL = (PACL)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, cbNewACL);
- if (!pNewACL)
- {
- goto end;
- }
-
- /**
- * STEP 8: Initialize the new ACL.
- */
- if (!GNInitializeAcl(pNewACL, cbNewACL, ACL_REVISION2))
- {
- goto end;
- }
-
- /**
- * STEP 9 If DACL is present, copy all the ACEs from the old DACL
- * to the new DACL.
- *
- * The following code assumes that the old DACL is
- * already in Windows 2000 preferred order. To conform
- * to the new Windows 2000 preferred order, first we will
- * copy all non-inherited ACEs from the old DACL to the
- * new DACL, irrespective of the ACE type.
- */
-
- newAceIndex = 0;
-
- if (fDaclPresent && AclInfo.AceCount)
- {
- for (CurrentAceIndex = 0;
- CurrentAceIndex < AclInfo.AceCount;
- CurrentAceIndex++)
- {
- /**
- * TEP 10: Get an ACE.
- */
- if (!GNGetAce(pACL, CurrentAceIndex, &pTempAce))
- {
- goto end;
- }
-
- /**
- * STEP 11: Check if it is a non-inherited ACE.
- * If it is an inherited ACE, break from the loop so
- * that the new access allowed non-inherited ACE can
- * be added in the correct position, immediately after
- * all non-inherited ACEs.
- */
- if (((ACCESS_ALLOWED_ACE *)pTempAce)->Header.AceFlags
- & INHERITED_ACE)
- break;
-
- /**
- * STEP 12: Skip adding the ACE, if the SID matches
- * with the account specified, as we are going to
- * add an access allowed ACE with a different access
- * mask.
- */
- if (GNEqualSid(pUserSID,
- &(((ACCESS_ALLOWED_ACE *)pTempAce)->SidStart)))
- continue;
-
- /**
- * STEP 13: Add the ACE to the new ACL.
- */
- if (!GNAddAce(pNewACL, ACL_REVISION, MAXDWORD, pTempAce,
- ((PACE_HEADER)pTempAce)->AceSize))
- {
- goto end;
- }
-
- newAceIndex++;
- }
- }
-
- /**
- * STEP 14: Add the access-allowed ACE to the new DACL.
- * The new ACE added here will be in the correct position,
- * immediately after all existing non-inherited ACEs.
- */
- if (!GNAddAccessAllowedAce(pNewACL, ACL_REVISION2, dwAccessMask,
- pUserSID))
- {
- goto end;
- }
-
- /**
- * STEP 14.5: Make new ACE inheritable
- */
- if (!GetAce(pNewACL, newAceIndex, &pTempAce))
- goto end;
- ((ACCESS_ALLOWED_ACE *)pTempAce)->Header.AceFlags |=
- (CONTAINER_INHERIT_ACE | OBJECT_INHERIT_ACE);
-
- /**
- * STEP 15: To conform to the new Windows 2000 preferred order,
- * we will now copy the rest of inherited ACEs from the
- * old DACL to the new DACL.
- */
- if (fDaclPresent && AclInfo.AceCount)
- {
- for (;
- CurrentAceIndex < AclInfo.AceCount;
- CurrentAceIndex++)
- {
- /**
- * STEP 16: Get an ACE.
- */
- if (!GNGetAce(pACL, CurrentAceIndex, &pTempAce))
- {
- goto end;
- }
-
- /**
- * STEP 17: Add the ACE to the new ACL.
- */
- if (!GNAddAce(pNewACL, ACL_REVISION, MAXDWORD, pTempAce,
- ((PACE_HEADER)pTempAce)->AceSize))
- {
- goto end;
- }
- }
- }
-
- /**
- * STEP 18: Set permissions
- */
- if (GNSetNamedSecurityInfo((LPTSTR)lpszFileName, SE_FILE_OBJECT,
- DACL_SECURITY_INFORMATION, NULL, NULL, pNewACL, NULL) != ERROR_SUCCESS)
- {
- goto end;
- }
-
- fResult = TRUE;
-
-end:
-
- /**
- * STEP 19: Free allocated memory
- */
- if (pUserSID)
- HeapFree(GetProcessHeap(), 0, pUserSID);
-
- if (szDomain)
- HeapFree(GetProcessHeap(), 0, szDomain);
-
- if (pFileSD)
- HeapFree(GetProcessHeap(), 0, pFileSD);
-
- if (pNewACL)
- HeapFree(GetProcessHeap(), 0, pNewACL);
-
- return fResult;
-}
-
-char *winErrorStr(const char *prefix, int dwErr)
-{
- char *err, *ret;
- int mem;
-
- if (!FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,
- NULL, (DWORD)dwErr, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPTSTR)&err,
- 0, NULL))
- {
- err = (char *)LocalAlloc(LMEM_FIXED | LMEM_ZEROINIT, 1);
- }
-
- mem = strlen(err) + strlen(prefix) + 20;
- ret = (char *)malloc(mem);
-
- snprintf(ret, mem, "%s: %s (#%u)", prefix, err, dwErr);
-
- LocalFree(err);
-
- return ret;
-}
-
-/**
- * Terminate a process by creating a remote thread within it,
- * which proceeds to call ExitProcess() inside that process.
- * Safer than TerminateProcess ().
- *
- * Code is from From http://private-storm.de/2009/08/11/case-terminateprocess/
- *
- * @param hProcess handle of a process to terminate
- * @param uExitCode exit code to use for ExitProcess()
- * @param dwTimeout number of ms to wait for the process to terminate
- * @return TRUE on success, FALSE on failure (check last error for the code)
- */
-BOOL
-SafeTerminateProcess(HANDLE hProcess, UINT uExitCode, DWORD dwTimeout)
-{
- DWORD dwTID, dwCode, dwErr = 0;
- HANDLE hProcessDup = INVALID_HANDLE_VALUE;
- HANDLE hRT = NULL;
- HINSTANCE hKernel = GetModuleHandle("Kernel32");
- BOOL bSuccess = FALSE;
-
- BOOL bDup = DuplicateHandle(GetCurrentProcess(), hProcess,
- GetCurrentProcess(), &hProcessDup, PROCESS_ALL_ACCESS,
- FALSE, 0);
-
- /* Detect the special case where the process is
- * already dead...
- */
- if (GetExitCodeProcess(bDup ? hProcessDup : hProcess, &dwCode) &&
- (STILL_ACTIVE == dwCode))
- {
- FARPROC pfnExitProc;
-
- pfnExitProc = GetProcAddress(hKernel, "ExitProcess");
-
- hRT = CreateRemoteThread((bDup) ? hProcessDup : hProcess, NULL, 0,
- (LPTHREAD_START_ROUTINE)pfnExitProc, (PVOID)uExitCode, 0, &dwTID);
-
- dwErr = GetLastError();
- }
- else
- {
- dwErr = ERROR_PROCESS_ABORTED;
- }
-
- if (hRT)
- {
- /* Must wait process to terminate to
- * guarantee that it has exited...
- */
- DWORD dwWaitResult = WaitForSingleObject((bDup) ? hProcessDup : hProcess,
- dwTimeout);
- if (dwWaitResult == WAIT_TIMEOUT)
- dwErr = WAIT_TIMEOUT;
- else
- dwErr = GetLastError();
-
- CloseHandle(hRT);
- bSuccess = dwErr == NO_ERROR;
- }
-
- if (bDup)
- CloseHandle(hProcessDup);
-
- SetLastError(dwErr);
-
- return bSuccess;
-}
-
-#endif
diff --git a/src/util/winproc.c b/src/util/winproc.c
deleted file mode 100644
index f2e4de4df..000000000
--- a/src/util/winproc.c
+++ /dev/null
@@ -1,340 +0,0 @@
-/*
- This file is part of GNUnet.
- Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006 GNUnet e.V.
-
- GNUnet is free software: you can redistribute it and/or modify it
- under the terms of the GNU Affero General Public License as published
- by the Free Software Foundation, either version 3 of the License,
- or (at your option) any later version.
-
- GNUnet is distributed in the hope that it will be useful, but
- WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- Affero General Public License for more details.
-
- You should have received a copy of the GNU Affero General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>.
-
- SPDX-License-Identifier: AGPL3.0-or-later
- */
-
-/**
- * @file util/winproc.c
- * @brief Functions for MS Windows
- * @author Nils Durner
- */
-
-#include "platform.h"
-#include "gnunet_crypto_lib.h"
-#include "gnunet_common.h"
-
-
-#ifdef MINGW
-
-static HINSTANCE hNTDLL, hIphlpapi, hAdvapi, hNetapi;
-#ifdef W32_VEH
-static void *GNWinVEH_handle = NULL;
-#endif
-
-TNtQuerySystemInformation GNNtQuerySystemInformation;
-TGetIfEntry GNGetIfEntry;
-TGetIpAddrTable GNGetIpAddrTable;
-TGetIfTable GNGetIfTable;
-TOpenSCManager GNOpenSCManager;
-TCreateService GNCreateService;
-TCloseServiceHandle GNCloseServiceHandle;
-TDeleteService GNDeleteService;
-TRegisterServiceCtrlHandler GNRegisterServiceCtrlHandler;
-TSetServiceStatus GNSetServiceStatus;
-TStartServiceCtrlDispatcher GNStartServiceCtrlDispatcher;
-TControlService GNControlService;
-TOpenService GNOpenService;
-TGetBestInterfaceEx GNGetBestInterfaceEx;
-TGetAdaptersInfo GNGetAdaptersInfo;
-TNetUserAdd GNNetUserAdd;
-TNetUserSetInfo GNNetUserSetInfo;
-TLsaOpenPolicy GNLsaOpenPolicy;
-TLsaAddAccountRights GNLsaAddAccountRights;
-TLsaRemoveAccountRights GNLsaRemoveAccountRights;
-TLsaClose GNLsaClose;
-TLookupAccountName GNLookupAccountName;
-TGetFileSecurity GNGetFileSecurity;
-TInitializeSecurityDescriptor GNInitializeSecurityDescriptor;
-TGetSecurityDescriptorDacl GNGetSecurityDescriptorDacl;
-TGetAclInformation GNGetAclInformation;
-TInitializeAcl GNInitializeAcl;
-TGetAce GNGetAce;
-TEqualSid GNEqualSid;
-TAddAce GNAddAce;
-TAddAccessAllowedAce GNAddAccessAllowedAce;
-TSetNamedSecurityInfo GNSetNamedSecurityInfo;
-
-#define LOG(kind, ...) GNUNET_log_from(kind, "util-winproc", __VA_ARGS__)
-/**
- * Log (panic) messages from PlibC
- */
-void
-plibc_panic(int err, char *msg)
-{
- LOG(((err == INT_MAX) ? GNUNET_ERROR_TYPE_DEBUG : GNUNET_ERROR_TYPE_ERROR),
- "%s", msg);
-}
-
-#ifdef W32_VEH
-/**
- * Handles exceptions (useful for debugging).
- * Issues a DebugBreak() call if the process is being debugged (not really
- * useful - if the process is being debugged, this handler won't be invoked
- * anyway). If it is not, runs a debugger from GNUNET_DEBUGGER env var,
- * substituting first %u in it for PID, and the second one for the event,
- * that should be set once the debugger attaches itself (otherwise the
- * only way out of WaitForSingleObject() is to time out after 1 minute).
- */
-LONG __stdcall
-GNWinVEH(PEXCEPTION_POINTERS ExceptionInfo)
-{
- char debugger[MAX_PATH + 1];
- char *debugger_env = NULL;
-
- if (IsDebuggerPresent())
- {
- DebugBreak();
- return EXCEPTION_CONTINUE_EXECUTION;
- }
- debugger_env = getenv("GNUNET_DEBUGGER");
- if (debugger_env != NULL)
- {
- STARTUPINFO si;
- PROCESS_INFORMATION pi;
- HANDLE event;
- SECURITY_ATTRIBUTES sa;
- memset(&si, 0, sizeof(si));
- si.cb = sizeof(si);
- memset(&pi, 0, sizeof(pi));
- memset(&sa, 0, sizeof(sa));
- sa.nLength = sizeof(sa);
- sa.bInheritHandle = TRUE;
- event = CreateEvent(&sa, FALSE, FALSE, NULL);
- snprintf(debugger, MAX_PATH + 1, debugger_env, GetCurrentProcessId(), (uintptr_t)event);
- debugger[MAX_PATH] = '\0';
- if (0 != CreateProcessA(NULL, debugger, NULL, NULL, TRUE, CREATE_NEW_CONSOLE, NULL, NULL, &si, &pi))
- {
- CloseHandle(pi.hProcess);
- CloseHandle(pi.hThread);
- WaitForSingleObject(event, 60000);
- CloseHandle(event);
- if (IsDebuggerPresent())
- {
- return EXCEPTION_CONTINUE_EXECUTION;
- }
- }
- else
- CloseHandle(event);
- }
- return EXCEPTION_CONTINUE_SEARCH;
-}
-#endif
-
-/**
- * @brief Initialize PlibC and set up Windows environment
- * @param logging context, NULL means stderr
- * @return Error code from winerror.h, ERROR_SUCCESS on success
- */
-int
-GNInitWinEnv()
-{
- int ret;
-
- plibc_initialized();
- plibc_set_panic_proc(plibc_panic);
- ret = plibc_init_utf8("GNU", PACKAGE, 1);
- plibc_set_stat_size_size(sizeof(((struct stat *)0)->st_size));
- plibc_set_stat_time_size(sizeof(((struct stat *)0)->st_mtime));
- /* don't load other DLLs twice */
- if (hNTDLL)
- return ret;
-
-#ifdef W32_VEH
- if (GNWinVEH_handle == NULL)
- {
- GNWinVEH_handle = AddVectoredExceptionHandler(1, &GNWinVEH);
- if (GNWinVEH_handle == NULL)
- {
- /* This is bad, but what can we do? */
- printf("Failed to set up an exception handler!\n");
- }
- }
-#endif
-
- hNTDLL = LoadLibrary("ntdll.dll");
-
- /* Function to get CPU usage under Win NT */
- if (hNTDLL)
- {
- GNNtQuerySystemInformation =
- (TNtQuerySystemInformation)GetProcAddress(hNTDLL,
- "NtQuerySystemInformation");
- }
- else
- {
- GNNtQuerySystemInformation = NULL;
- }
-
- /* Functions to get information about a network adapter */
- hIphlpapi = LoadLibrary("iphlpapi.dll");
- if (hIphlpapi)
- {
- GNGetIfEntry = (TGetIfEntry)GetProcAddress(hIphlpapi, "GetIfEntry");
- GNGetIpAddrTable =
- (TGetIpAddrTable)GetProcAddress(hIphlpapi, "GetIpAddrTable");
- GNGetIfTable = (TGetIfTable)GetProcAddress(hIphlpapi, "GetIfTable");
- GNGetBestInterfaceEx =
- (TGetBestInterfaceEx)GetProcAddress(hIphlpapi, "GetBestInterfaceEx");
- GNGetAdaptersInfo =
- (TGetAdaptersInfo)GetProcAddress(hIphlpapi, "GetAdaptersInfo");
- }
- else
- {
- GNGetIfEntry = NULL;
- GNGetIpAddrTable = NULL;
- GNGetIfTable = NULL;
- GNGetBestInterfaceEx = NULL;
- GNGetAdaptersInfo = NULL;
- }
-
- /* Service & Account functions */
- hAdvapi = LoadLibrary("advapi32.dll");
- if (hAdvapi)
- {
- GNOpenSCManager =
- (TOpenSCManager)GetProcAddress(hAdvapi, "OpenSCManagerA");
- GNCreateService =
- (TCreateService)GetProcAddress(hAdvapi, "CreateServiceA");
- GNCloseServiceHandle =
- (TCloseServiceHandle)GetProcAddress(hAdvapi, "CloseServiceHandle");
- GNDeleteService =
- (TDeleteService)GetProcAddress(hAdvapi, "DeleteService");
- GNRegisterServiceCtrlHandler =
- (TRegisterServiceCtrlHandler)GetProcAddress(hAdvapi,
- "RegisterServiceCtrlHandlerA");
- GNSetServiceStatus =
- (TSetServiceStatus)GetProcAddress(hAdvapi, "SetServiceStatus");
- GNStartServiceCtrlDispatcher =
- (TStartServiceCtrlDispatcher)GetProcAddress(hAdvapi,
- "StartServiceCtrlDispatcherA");
- GNControlService =
- (TControlService)GetProcAddress(hAdvapi, "ControlService");
- GNOpenService = (TOpenService)GetProcAddress(hAdvapi, "OpenServiceA");
-
- GNLsaOpenPolicy =
- (TLsaOpenPolicy)GetProcAddress(hAdvapi, "LsaOpenPolicy");
- GNLsaAddAccountRights =
- (TLsaAddAccountRights)GetProcAddress(hAdvapi, "LsaAddAccountRights");
- GNLsaRemoveAccountRights =
- (TLsaRemoveAccountRights)GetProcAddress(hAdvapi,
- "LsaRemoveAccountRights");
- GNLsaClose = (TLsaClose)GetProcAddress(hAdvapi, "LsaClose");
- GNLookupAccountName =
- (TLookupAccountName)GetProcAddress(hAdvapi, "LookupAccountNameA");
-
- GNGetFileSecurity =
- (TGetFileSecurity)GetProcAddress(hAdvapi, "GetFileSecurityA");
- GNInitializeSecurityDescriptor =
- (TInitializeSecurityDescriptor)GetProcAddress(hAdvapi,
- "InitializeSecurityDescriptor");
- GNGetSecurityDescriptorDacl =
- (TGetSecurityDescriptorDacl)GetProcAddress(hAdvapi,
- "GetSecurityDescriptorDacl");
- GNGetAclInformation =
- (TGetAclInformation)GetProcAddress(hAdvapi, "GetAclInformation");
- GNInitializeAcl =
- (TInitializeAcl)GetProcAddress(hAdvapi, "InitializeAcl");
- GNGetAce = (TGetAce)GetProcAddress(hAdvapi, "GetAce");
- GNEqualSid = (TEqualSid)GetProcAddress(hAdvapi, "EqualSid");
- GNAddAce = (TAddAce)GetProcAddress(hAdvapi, "AddAce");
- GNAddAccessAllowedAce =
- (TAddAccessAllowedAce)GetProcAddress(hAdvapi, "AddAccessAllowedAce");
- GNSetNamedSecurityInfo =
- (TSetNamedSecurityInfo)GetProcAddress(hAdvapi,
- "SetNamedSecurityInfoA");
- }
- else
- {
- GNOpenSCManager = NULL;
- GNCreateService = NULL;
- GNCloseServiceHandle = NULL;
- GNDeleteService = NULL;
- GNRegisterServiceCtrlHandler = NULL;
- GNSetServiceStatus = NULL;
- GNStartServiceCtrlDispatcher = NULL;
- GNControlService = NULL;
- GNOpenService = NULL;
-
- GNLsaOpenPolicy = NULL;
- GNLsaAddAccountRights = NULL;
- GNLsaRemoveAccountRights = NULL;
- GNLsaClose = NULL;
- GNLookupAccountName = NULL;
-
- GNGetFileSecurity = NULL;
- GNInitializeSecurityDescriptor = NULL;
- GNGetSecurityDescriptorDacl = NULL;
- GNGetAclInformation = NULL;
- GNInitializeAcl = NULL;
- GNGetAce = NULL;
- GNEqualSid = NULL;
- GNAddAce = NULL;
- GNAddAccessAllowedAce = NULL;
- GNSetNamedSecurityInfo = NULL;
- }
-
- /* Account function */
- hNetapi = LoadLibrary("netapi32.dll");
- if (hNetapi)
- {
- GNNetUserAdd = (TNetUserAdd)GetProcAddress(hNetapi, "NetUserAdd");
- GNNetUserSetInfo =
- (TNetUserSetInfo)GetProcAddress(hNetapi, "NetUserSetInfo");
- }
- else
- {
- GNNetUserAdd = NULL;
- GNNetUserSetInfo = NULL;
- }
-
- return ret;
-}
-
-/**
- * Clean up Windows environment
- */
-void
-GNShutdownWinEnv()
-{
- plibc_shutdown();
-
-#ifdef W32_VEH
- if (GNWinVEH_handle != NULL)
- {
- RemoveVectoredExceptionHandler(GNWinVEH_handle);
- GNWinVEH_handle = NULL;
- }
-#endif
-
- FreeLibrary(hNTDLL);
- FreeLibrary(hIphlpapi);
- FreeLibrary(hAdvapi);
- FreeLibrary(hNetapi);
-
- CoUninitialize();
-}
-
-#endif /* MINGW */
-
-#if !HAVE_ATOLL
-long long
-atoll(const char *nptr)
-{
- return atol(nptr);
-}
-#endif
diff --git a/src/vpn/Makefile.am b/src/vpn/Makefile.am
index d1f74d35b..3ad9b1a54 100644
--- a/src/vpn/Makefile.am
+++ b/src/vpn/Makefile.am
@@ -1,11 +1,6 @@
# This Makefile.am is in the public domain
AM_CPPFLAGS = -I$(top_srcdir)/src/include -I$(top_builddir)/src/include
-if MINGW
- WINFLAGS = -Wl,--no-undefined,--export-all-symbols
- VPNBIN = gnunet-helper-vpn
-endif
-
if USE_COVERAGE
AM_CFLAGS = --coverage -O0
endif
@@ -39,20 +34,9 @@ libexec_PROGRAMS = \
bin_PROGRAMS = \
gnunet-vpn
-if MINGW
- gnunet_helper_vpn_LDFLAGS = \
- -no-undefined -Wl,--export-all-symbols
-
- gnunet_helper_vpn_LDADD = \
- -lsetupapi -lnewdev -lshell32 -liconv -lstdc++ \
- -lcomdlg32 -lgdi32 -liphlpapi
+gnunet_helper_vpn_SOURCES = \
+gnunet-helper-vpn.c
- gnunet_helper_vpn_SOURCES = \
- gnunet-helper-vpn-windows.c
-else
- gnunet_helper_vpn_SOURCES = \
- gnunet-helper-vpn.c
-endif
gnunet_service_vpn_SOURCES = \
gnunet-service-vpn.c
gnunet_service_vpn_LDADD = \
diff --git a/src/vpn/gnunet-helper-vpn-windows.c b/src/vpn/gnunet-helper-vpn-windows.c
deleted file mode 100644
index afa4fa139..000000000
--- a/src/vpn/gnunet-helper-vpn-windows.c
+++ /dev/null
@@ -1,1610 +0,0 @@
-/*
- This file is part of GNUnet.
- Copyright (C) 2010, 2012 Christian Grothoff
-
- GNUnet is free software: you can redistribute it and/or modify it
- under the terms of the GNU Affero General Public License as published
- by the Free Software Foundation, either version 3 of the License,
- or (at your option) any later version.
-
- GNUnet is distributed in the hope that it will be useful, but
- WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- Affero General Public License for more details.
-
- You should have received a copy of the GNU Affero General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>.
-
- SPDX-License-Identifier: AGPL3.0-or-later
- */
-/**
- * @file vpn/gnunet-helper-vpn-windows.c
- * @brief the helper for the VPN service in win32 builds.
- * Opens a virtual network-interface, sends data received on the if to stdout,
- * sends data received on stdin to the interface
- * @author Christian M. Fuchs
- *
- * The following list of people have reviewed this code and considered
- * it safe since the last modification (if you reviewed it, please
- * have your name added to the list):
- *
- */
-
-#include <stdio.h>
-#include <Winsock2.h>
-#include <windows.h>
-#include <setupapi.h>
-#ifndef __MINGW64_VERSION_MAJOR
-#include <ddk/cfgmgr32.h>
-#include <ddk/newdev.h>
-#else
-#include <cfgmgr32.h>
-#include <newdev.h>
-#endif
-#include <time.h>
-#include "platform.h"
-#include "tap-windows.h"
-/**
- * Need 'struct GNUNET_HashCode' and 'struct GNUNET_PeerIdentity'.
- */
-#include "gnunet_crypto_lib.h"
-/**
- * Need 'struct GNUNET_MessageHeader'.
- */
-#include "gnunet_common.h"
-
-/**
- * Need VPN message types.
- */
-#include "gnunet_protocols.h"
-
-/**
- * Should we print (interesting|debug) messages that can happen during
- * normal operation?
- */
-#define DEBUG GNUNET_NO
-
-#if DEBUG
-/* FIXME: define with varargs... */
-#define LOG_DEBUG(msg) fprintf(stderr, "%s", msg);
-#else
-#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_MAX_MESSAGE_SIZE)
- */
-#define MAX_SIZE 65536
-
-/**
- * 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/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/openvpn-tap32/tapw64/OemWin2k.inf"
-
-/**
- * Hardware ID used in the inf-file.
- * This might change over time, as openvpn advances their driver
- */
-#define HARDWARE_ID "tap0901"
-
-/**
- * Minimum major-id of the driver version we can work with
- */
-#define TAP_WIN_MIN_MAJOR 9
-
-/**
- * Minimum minor-id of the driver version we can work with.
- * v <= 7 has buggy IPv6.
- * v == 8 is broken for small IPv4 Packets
- */
-#define TAP_WIN_MIN_MINOR 9
-
-/**
- * Time in seconds to wait for our virtual device to go up after telling it to do so.
- *
- * openvpn doesn't specify a value, 4 seems sane for testing, even for openwrt
- * (in fact, 4 was chosen by a fair dice roll...)
- */
-#define TAP32_POSTUP_WAITTIME 4
-
-/**
- * Location of the network interface list resides in registry.
- */
-#define INTERFACE_REGISTRY_LOCATION "SYSTEM\\CurrentControlSet\\Control\\Network\\{4D36E972-E325-11CE-BFC1-08002BE10318}"
-
-/**
- * Our local process' PID. Used for creating a sufficiently unique additional
- * hardware ID for our device.
- */
-static char secondary_hwid[LINE_LEN / 2];
-
-/**
- * Device's visible Name, used to identify a network device in netsh.
- * eg: "Local Area Connection 9"
- */
-static char device_visible_name[256];
-
-/**
- * This is our own local instance of a virtual network interface
- * It is (somewhat) equivalent to using tun/tap in unixoid systems
- *
- * Upon initialization, we create such an device node.
- * Upon termination, we remove it again.
- *
- * If we crash this device might stay around.
- */
-static HDEVINFO DeviceInfo = INVALID_HANDLE_VALUE;
-
-/**
- * Registry Key we hand over to windows to spawn a new virtual interface
- */
-static SP_DEVINFO_DATA DeviceNode;
-
-/**
- * GUID of our virtual device in the form of
- * {12345678-1234-1234-1234-123456789abc} - in hex
- */
-static char device_guid[256];
-
-
-/**
- * Possible states of an IO facility.
- */
-enum IO_State {
- /**
- * overlapped I/O is ready for work
- */
- IOSTATE_READY = 0,
-
- /**
- * overlapped I/O has been queued
- */
- IOSTATE_QUEUED,
-
- /**
- * overlapped I/O has finished, but is waiting for it's write-partner
- */
- IOSTATE_WAITING,
-
- /**
- * there is a full buffer waiting
- */
- IOSTATE_RESUME,
-
- /**
- * Operlapped IO states for facility objects
- * overlapped I/O has failed, stop processing
- */
- IOSTATE_FAILED
-};
-
-
-/**
- * A IO Object + read/writebuffer + buffer-size for windows asynchronous IO handling
- */
-struct io_facility {
- /**
- * The mode the state machine associated with this object is in.
- */
- enum IO_State facility_state;
-
- /**
- * If the path is open or blocked in general (used for quickly checking)
- */
- BOOL path_open; // BOOL is winbool (int), NOT boolean (unsigned char)!
-
- /**
- * Windows Object-Handle (used for accessing TAP and STDIN/STDOUT)
- */
- HANDLE handle;
-
- /**
- * Overlaped IO structure used for asynchronous IO in windows.
- */
- OVERLAPPED overlapped;
-
- /**
- * Buffer for reading things to and writing from...
- */
- unsigned char buffer[MAX_SIZE];
-
- /**
- * How much of this buffer was used when reading or how much data can be written
- */
- DWORD buffer_size;
-
- /**
- * Amount of data actually written or read by readfile/writefile.
- */
- DWORD buffer_size_processed;
-
- /**
- * How much of this buffer we have writte in total
- */
- DWORD buffer_size_written;
-};
-
-/**
- * ReOpenFile is only available as of XP SP2 and 2003 SP1
- */
-WINBASEAPI HANDLE WINAPI ReOpenFile(HANDLE, DWORD, DWORD, DWORD);
-
-/**
- * IsWow64Process definition for our is_win64, as this is a kernel function
- */
-typedef BOOL (WINAPI *LPFN_ISWOW64PROCESS)(HANDLE, PBOOL);
-
-
-/**
- * Like strlcpy but portable. The given string @a src is copied until its null
- * byte or until @a n - 1 bytes have been read. The destination buffer is
- * guaranteed to be null-terminated.
- *
- * @param dst destination of the copy (must be @a n bytes long)
- * @param src source of the copy (at most @a n - 1 bytes will be read)
- * @param n the length of the string to copy, including its terminating null
- * byte
- * @return the length of the string that was copied, excluding the terminating
- * null byte
- */
-size_t
-GNUNET_strlcpy(char *dst, const char *src, size_t n)
-{
- size_t ret;
- size_t slen;
-
- GNUNET_assert(0 != n);
- slen = strnlen(src, n - 1);
- memcpy(dst, src, slen);
- dst[slen] = '\0';
- return slen;
-}
-
-
-/**
- * Determines if the host OS is win32 or win64
- *
- * @return true if
- */
-BOOL
-is_win64()
-{
-#if defined(_WIN64)
- //this is a win64 binary,
- return TRUE;
-#elif defined(_WIN32)
- //this is a 32bit binary, and we need to check if we are running in WOW64
- BOOL success = FALSE;
- BOOL on_wow64 = FALSE;
- LPFN_ISWOW64PROCESS IsWow64Process = (LPFN_ISWOW64PROCESS)GetProcAddress(GetModuleHandle("kernel32"), "IsWow64Process");
-
- if (NULL != IsWow64Process)
- success = IsWow64Process(GetCurrentProcess(), &on_wow64);
-
- return success && on_wow64;
-#endif
-}
-/**
- * Wrapper for executing a shellcommand in windows.
- *
- * @param command - the command + parameters to execute
- * @return * exitcode of the program executed,
- * * EINVAL (cmd/file not found)
- * * EPIPE (could not read STDOUT)
- */
-static int
-execute_shellcommand(const char *command)
-{
- FILE *pipe;
-
- if ((NULL == command) ||
- (NULL == (pipe = _popen(command, "rt"))))
- return EINVAL;
-
-#if DEBUG
- fprintf(stderr, "DEBUG: Command output: \n");
- char output[LINE_LEN];
- while (NULL != fgets(output, sizeof(output), pipe))
- fprintf(stderr, "%s", output);
-#endif
-
- return _pclose(pipe);
-}
-
-
-/**
- * @brief Sets the IPv6-Address given in address on the interface dev
- *
- * @param address the IPv6-Address
- * @param prefix_len the length of the network-prefix
- */
-static int
-set_address6(const char *address, unsigned long prefix_len)
-{
- int ret = EINVAL;
- char command[LINE_LEN];
- struct sockaddr_in6 sa6;
-
- /*
- * parse the new address
- */
- memset(&sa6, 0, sizeof(struct sockaddr_in6));
- sa6.sin6_family = AF_INET6;
- if (1 != inet_pton(AF_INET6, address, &sa6.sin6_addr.s6_addr))
- {
- fprintf(stderr, "ERROR: Failed to parse address `%s': %s\n", address,
- strerror(errno));
- return -1;
- }
-
- /*
- * prepare the command
- */
- snprintf(command, LINE_LEN,
- "netsh interface ipv6 add address \"%s\" %s/%d store=active",
- device_visible_name, address, prefix_len);
- /*
- * Set the address
- */
- ret = execute_shellcommand(command);
-
- /* Did it work?*/
- if (0 != ret)
- fprintf(stderr, "FATAL: Setting IPv6 address failed: %s\n", strerror(ret));
- return ret;
-}
-
-
-/**
- * @brief Removes the IPv6-Address given in address from the interface dev
- *
- * @param address the IPv4-Address
- */
-static void
-remove_address6(const char *address)
-{
- char command[LINE_LEN];
- int ret = EINVAL;
-
- // sanity checking was already done in set_address6
- /*
- * prepare the command
- */
- snprintf(command, LINE_LEN,
- "netsh interface ipv6 delete address \"%s\" store=persistent",
- device_visible_name);
- /*
- * Set the address
- */
- ret = execute_shellcommand(command);
-
- /* Did it work?*/
- if (0 != ret)
- fprintf(stderr,
- "FATAL: removing IPv6 address failed: %s\n",
- strerror(ret));
-}
-
-
-/**
- * @brief Sets the IPv4-Address given in address on the interface dev
- *
- * @param address the IPv4-Address
- * @param mask the netmask
- */
-static int
-set_address4(const char *address, const char *mask)
-{
- int ret = EINVAL;
- char command[LINE_LEN];
-
- struct sockaddr_in addr;
-
- addr.sin_family = AF_INET;
-
- /*
- * Parse the address
- */
- if (1 != inet_pton(AF_INET, address, &addr.sin_addr.s_addr))
- {
- fprintf(stderr, "ERROR: Failed to parse address `%s': %s\n", address,
- strerror(errno));
- return -1;
- }
- // Set Device to Subnet-Mode? do we really need openvpn/tun.c:2925 ?
-
- /*
- * prepare the command
- */
- snprintf(command, LINE_LEN,
- "netsh interface ipv4 add address \"%s\" %s %s store=active",
- device_visible_name, address, mask);
- /*
- * Set the address
- */
- ret = execute_shellcommand(command);
-
- /* Did it work?*/
- if (0 != ret)
- fprintf(stderr,
- "FATAL: Setting IPv4 address failed: %s\n",
- strerror(ret));
- return ret;
-}
-
-
-/**
- * @brief Removes the IPv4-Address given in address from the interface dev
- *
- * @param address the IPv4-Address
- */
-static void
-remove_address4(const char *address)
-{
- char command[LINE_LEN];
- int ret = EINVAL;
-
- // sanity checking was already done in set_address4
-
- /*
- * prepare the command
- */
- snprintf(command, LINE_LEN,
- "netsh interface ipv4 delete address \"%s\" gateway=all store=persistent",
- device_visible_name);
- /*
- * Set the address
- */
- ret = execute_shellcommand(command);
-
- /* Did it work?*/
- if (0 != ret)
- fprintf(stderr, "FATAL: removing IPv4 address failed: %s\n", strerror(ret));
-}
-
-
-/**
- * Setup a new virtual interface to use for tunneling.
- *
- * @return: TRUE if setup was successful, else FALSE
- */
-static BOOL
-setup_interface()
-{
- /*
- * where to find our inf-file. (+ the "full" path, after windows found")
- *
- * We do not directly input all the props here, because openvpn will update
- * these details over time.
- */
- char inf_file_path[MAX_PATH];
- char * temp_inf_filename;
- char hwidlist[LINE_LEN + 4];
- char class_name[128];
- GUID class_guid;
- int str_length = 0;
-
- /**
- * Set the device's hardware ID and add it to a list.
- * This information will later on identify this device in registry.
- */
- str_len = GNUNET_strlcpy(hwidlist,
- HARDWARE_ID,
- sizeof(hwidList)) + 1;
- /**
- * this is kind of over-complicated, but allows keeps things independent of
- * how the openvpn-hwid is actually stored.
- *
- * A HWID list is double-\0 terminated and \0 separated
- */
- str_len += GNUNET_strlcpy(&hwidlist[str_length],
- secondary_hwid,
- sizeof(hwidlist) - str_len) + 1;
- GNUNET_assert(str_len < sizeof(hwidlist));
- hwidlist[str_len] = '\0';
- ++str_len;
-
- /**
- * Locate the inf-file, we need to store it somewhere where the system can
- * find it. We need to pick the correct driver for win32/win64.
- */
- if (is_win64())
- GetFullPathNameA(INF_FILE64, MAX_PATH, inf_file_path, &temp_inf_filename);
- else
- GetFullPathNameA(INF_FILE, MAX_PATH, inf_file_path, &temp_inf_filename);
-
- fprintf(stderr, "INFO: Located our driver's .inf file at %s\n", inf_file_path);
- /**
- * Bootstrap our device info using the drivers inf-file
- */
- if (!SetupDiGetINFClassA(inf_file_path,
- &class_guid,
- class_name, sizeof(class_name) / sizeof(char),
- NULL))
- return FALSE;
-
- /**
- * Collect all the other needed information...
- * let the system fill our this form
- */
- DeviceInfo = SetupDiCreateDeviceInfoList(&class_guid, NULL);
- if (DeviceInfo == INVALID_HANDLE_VALUE)
- return FALSE;
-
- DeviceNode.cbSize = sizeof(SP_DEVINFO_DATA);
- if (!SetupDiCreateDeviceInfoA(DeviceInfo,
- class_name,
- &class_guid,
- NULL,
- 0,
- DICD_GENERATE_ID,
- &DeviceNode))
- return FALSE;
-
- /* Deploy all the information collected into the registry */
- if (!SetupDiSetDeviceRegistryPropertyA(DeviceInfo,
- &DeviceNode,
- SPDRP_HARDWAREID,
- (LPBYTE)hwidlist,
- str_length * sizeof(char)))
- return FALSE;
-
- /* Install our new class(=device) into the system */
- if (!SetupDiCallClassInstaller(DIF_REGISTERDEVICE,
- DeviceInfo,
- &DeviceNode))
- return FALSE;
-
- /* This system call tends to take a while (several seconds!) on
- "modern" Windoze systems */
- if (!UpdateDriverForPlugAndPlayDevicesA(NULL,
- secondary_hwid,
- inf_file_path,
- INSTALLFLAG_FORCE | INSTALLFLAG_NONINTERACTIVE,
- NULL)) //reboot required? NEVER!
- return FALSE;
-
- fprintf(stderr, "DEBUG: successfully created a network device\n");
- return TRUE;
-}
-
-
-/**
- * Remove our new virtual interface to use for tunneling.
- * This function must be called AFTER setup_interface!
- *
- * @return: TRUE if destruction was successful, else FALSE
- */
-static BOOL
-remove_interface()
-{
- SP_REMOVEDEVICE_PARAMS remove;
-
- if (INVALID_HANDLE_VALUE == DeviceInfo)
- return FALSE;
-
- remove.ClassInstallHeader.cbSize = sizeof(SP_CLASSINSTALL_HEADER);
- remove.HwProfile = 0;
- remove.Scope = DI_REMOVEDEVICE_GLOBAL;
- remove.ClassInstallHeader.InstallFunction = DIF_REMOVE;
- /*
- * 1. Prepare our existing device information set, and place the
- * uninstall related information into the structure
- */
- if (!SetupDiSetClassInstallParamsA(DeviceInfo,
- (PSP_DEVINFO_DATA)&DeviceNode,
- &remove.ClassInstallHeader,
- sizeof(remove)))
- return FALSE;
- /*
- * 2. Uninstall the virtual interface using the class installer
- */
- if (!SetupDiCallClassInstaller(DIF_REMOVE,
- DeviceInfo,
- (PSP_DEVINFO_DATA)&DeviceNode))
- return FALSE;
-
- SetupDiDestroyDeviceInfoList(DeviceInfo);
-
- fprintf(stderr, "DEBUG: removed interface successfully\n");
-
- return TRUE;
-}
-
-
-/**
- * Do all the lookup necessary to retrieve the inteface's actual name
- * off the registry.
- *
- * @return: TRUE if we were able to lookup the interface's name, else FALSE
- */
-static BOOL
-resolve_interface_name()
-{
- SP_DEVINFO_LIST_DETAIL_DATA device_details;
- char pnp_instance_id [MAX_DEVICE_ID_LEN];
- HKEY adapter_key_handle;
- LONG status;
- DWORD len;
- int i = 0;
- int retrys;
- BOOL retval = FALSE;
- char adapter[] = INTERFACE_REGISTRY_LOCATION;
-
- /* We can obtain the PNP instance ID from our setupapi handle */
- device_details.cbSize = sizeof(device_details);
- if (CR_SUCCESS != CM_Get_Device_ID_ExA(DeviceNode.DevInst,
- (PCHAR)pnp_instance_id,
- MAX_DEVICE_ID_LEN,
- 0, //must be 0
- NULL)) //hMachine, we are local
- return FALSE;
-
- fprintf(stderr, "DEBUG: Resolving interface name for network device %s\n", pnp_instance_id);
-
- /* Registry is incredibly slow, retry for up to 30 seconds to allow registry to refresh */
- for (retrys = 0; retrys < 120 && !retval; retrys++)
- {
- /* sleep for 250ms*/
- Sleep(250);
-
- /* Now we can use this ID to locate the correct networks interface in registry */
- if (ERROR_SUCCESS != RegOpenKeyExA(
- HKEY_LOCAL_MACHINE,
- adapter,
- 0,
- KEY_READ,
- &adapter_key_handle))
- return FALSE;
-
- /* Of course there is a multitude of entries here, with arbitrary names,
- * thus we need to iterate through there.
- */
- while (!retval)
- {
- char instance_key[256];
- char query_key [256];
- HKEY instance_key_handle;
- char pnpinstanceid_name[] = "PnpInstanceID";
- char pnpinstanceid_value[256];
- char adaptername_name[] = "Name";
- DWORD data_type;
-
- len = 256 * sizeof(char);
- /* optain a subkey of {4D36E972-E325-11CE-BFC1-08002BE10318} */
- status = RegEnumKeyExA(
- adapter_key_handle,
- i,
- instance_key,
- &len,
- NULL,
- NULL,
- NULL,
- NULL);
-
- /* this may fail due to one of two reasons:
- * we are at the end of the list*/
- if (ERROR_NO_MORE_ITEMS == status)
- break;
- // * we found a broken registry key, continue with the next key.
- if (ERROR_SUCCESS != status)
- goto cleanup;
-
- /* prepare our new query string: */
- snprintf(query_key, 256, "%s\\%s\\Connection",
- adapter,
- instance_key);
-
- /* look inside instance_key\\Connection */
- if (ERROR_SUCCESS != RegOpenKeyExA(
- HKEY_LOCAL_MACHINE,
- query_key,
- 0,
- KEY_READ,
- &instance_key_handle))
- goto cleanup;
-
- /* now, read our PnpInstanceID */
- len = sizeof(pnpinstanceid_value);
- status = RegQueryValueExA(instance_key_handle,
- pnpinstanceid_name,
- NULL, //reserved, always NULL according to MSDN
- &data_type,
- (LPBYTE)pnpinstanceid_value,
- &len);
-
- if (status != ERROR_SUCCESS || data_type != REG_SZ)
- goto cleanup;
-
- /* compare the value we got to our devices PNPInstanceID*/
- if (0 != strncmp(pnpinstanceid_value, pnp_instance_id,
- sizeof(pnpinstanceid_value) / sizeof(char)))
- goto cleanup;
-
- len = sizeof(device_visible_name);
- status = RegQueryValueExA(
- instance_key_handle,
- adaptername_name,
- NULL, //reserved, always NULL according to MSDN
- &data_type,
- (LPBYTE)device_visible_name,
- &len);
-
- if (status != ERROR_SUCCESS || data_type != REG_SZ)
- goto cleanup;
-
- /*
- * we have successfully found OUR instance,
- * save the device GUID before exiting
- */
- GNUNET_strlcpy(device_guid, instance_key, sizeof(device_guid));
- retval = TRUE;
- fprintf(stderr, "DEBUG: Interface Name lookup succeeded on retry %d, got \"%s\" %s\n", retrys, device_visible_name, device_guid);
-
-cleanup:
- RegCloseKey(instance_key_handle);
-
- ++i;
- }
-
- RegCloseKey(adapter_key_handle);
- }
- return retval;
-}
-
-
-/**
- * Determines the version of the installed TAP32 driver and checks if it's sufficiently new for GNUNET
- *
- * @param handle the handle to our tap device
- * @return TRUE if the version is sufficient, else FALSE
- */
-static BOOL
-check_tapw32_version(HANDLE handle)
-{
- ULONG version[3];
- DWORD len;
-
- memset(&(version), 0, sizeof(version));
-
- if (DeviceIoControl(handle, TAP_WIN_IOCTL_GET_VERSION,
- &version, sizeof(version),
- &version, sizeof(version), &len, NULL))
- fprintf(stderr, "INFO: TAP-Windows Driver Version %d.%d %s\n",
- (int)version[0],
- (int)version[1],
- (version[2] ? "(DEBUG)" : ""));
-
- if ((version[0] != TAP_WIN_MIN_MAJOR) ||
- (version[1] < TAP_WIN_MIN_MINOR))
- {
- fprintf(stderr, "FATAL: This version of gnunet requires a TAP-Windows driver that is at least version %d.%d\n",
- TAP_WIN_MIN_MAJOR,
- TAP_WIN_MIN_MINOR);
- return FALSE;
- }
-
- return TRUE;
-}
-
-
-/**
- * Creates a tun-interface called dev;
- *
- * @return the fd to the tun or -1 on error
- */
-static HANDLE
-init_tun()
-{
- char device_path[256];
- HANDLE handle;
-
- if (!setup_interface())
- {
- errno = ENODEV;
- return INVALID_HANDLE_VALUE;
- }
-
- if (!resolve_interface_name())
- {
- errno = ENODEV;
- return INVALID_HANDLE_VALUE;
- }
-
- /* Open Windows TAP-Windows adapter */
- snprintf(device_path, sizeof(device_path), "%s%s%s",
- USERMODEDEVICEDIR,
- device_guid,
- TAP_WIN_SUFFIX);
-
- handle = CreateFile(
- device_path,
- GENERIC_READ | GENERIC_WRITE,
- 0, /* was: FILE_SHARE_READ */
- 0,
- OPEN_EXISTING,
- FILE_ATTRIBUTE_SYSTEM | FILE_FLAG_OVERLAPPED,
- 0
- );
-
- if (INVALID_HANDLE_VALUE == handle)
- {
- fprintf(stderr, "FATAL: CreateFile failed on TAP device: %s\n", device_path);
- return handle;
- }
-
- /* get driver version info */
- if (!check_tapw32_version(handle))
- {
- CloseHandle(handle);
- return INVALID_HANDLE_VALUE;
- }
-
- /* TODO (opt?): get MTU-Size */
-
- fprintf(stderr, "DEBUG: successfully opened TAP device\n");
- return handle;
-}
-
-
-/**
- * Brings a TAP device up and sets it to connected state.
- *
- * @param handle the handle to our TAP device
- * @return True if the operation succeeded, else false
- */
-static BOOL
-tun_up(HANDLE handle)
-{
- ULONG status = TRUE;
- DWORD len;
-
- if (!DeviceIoControl(handle, TAP_WIN_IOCTL_SET_MEDIA_STATUS,
- &status, sizeof(status),
- &status, sizeof(status), &len, NULL))
- {
- fprintf(stderr, "FATAL: TAP driver ignored request to UP interface (DeviceIoControl call)\n");
- return FALSE;
- }
-
- /* Wait for the device to go UP, might take some time. */
- Sleep(TAP32_POSTUP_WAITTIME * 1000);
- fprintf(stderr, "DEBUG: successfully set TAP device to UP\n");
-
- return TRUE;
-}
-
-
-/**
- * Attempts to read off an input facility (tap or named pipe) in overlapped mode.
- *
- * 1.
- * If the input facility is in IOSTATE_READY, it will issue a new read operation to the
- * input handle. Then it goes into IOSTATE_QUEUED state.
- * In case the read succeeded instantly the input facility enters 3.
- *
- * 2.
- * If the input facility is in IOSTATE_QUEUED state, it will check if the queued read has finished already.
- * If it has finished, go to state 3.
- * If it has failed, set IOSTATE_FAILED
- *
- * 3.
- * If the output facility is in state IOSTATE_READY, the read-buffer is copied to the output buffer.
- * The input facility enters state IOSTATE_READY
- * The output facility enters state IOSTATE_READY
- * If the output facility is in state IOSTATE_QUEUED, the input facility enters IOSTATE_WAITING
- *
- * IOSTATE_WAITING is reset by the output facility, once it has completed.
- *
- * @param input_facility input named pipe or file to work with.
- * @param output_facility output pipe or file to hand over data to.
- * @return false if an event reset was impossible (OS error), else true
- */
-static BOOL
-attempt_read_tap(struct io_facility * input_facility,
- struct io_facility * output_facility)
-{
- struct GNUNET_MessageHeader * hdr;
- unsigned short size;
-
- switch (input_facility->facility_state)
- {
- case IOSTATE_READY:
- {
- if (!ResetEvent(input_facility->overlapped.hEvent))
- {
- return FALSE;
- }
-
- input_facility->buffer_size = 0;
-
- /* Check how the task is handled */
- if (ReadFile(input_facility->handle,
- input_facility->buffer,
- sizeof(input_facility->buffer) - sizeof(struct GNUNET_MessageHeader),
- &input_facility->buffer_size,
- &input_facility->overlapped))
- { /* async event processed immediately*/
- /* reset event manually*/
- if (!SetEvent(input_facility->overlapped.hEvent))
- return FALSE;
-
- fprintf(stderr, "DEBUG: tap read succeeded immediately\n");
-
- /* we successfully read something from the TAP and now need to
- * send it our via STDOUT. Is that possible at the moment? */
- if ((IOSTATE_READY == output_facility->facility_state ||
- IOSTATE_WAITING == output_facility->facility_state)
- && (0 < input_facility->buffer_size))
- { /* hand over this buffers content and apply message header for gnunet */
- hdr = (struct GNUNET_MessageHeader *)output_facility->buffer;
- size = input_facility->buffer_size + sizeof(struct GNUNET_MessageHeader);
-
- GNUNET_memcpy(output_facility->buffer + sizeof(struct GNUNET_MessageHeader),
- input_facility->buffer,
- input_facility->buffer_size);
-
- output_facility->buffer_size = size;
- hdr->size = htons(size);
- hdr->type = htons(GNUNET_MESSAGE_TYPE_VPN_HELPER);
- output_facility->facility_state = IOSTATE_READY;
- }
- else if (0 < input_facility->buffer_size)
- /* If we have have read our buffer, wait for our write-partner*/
- input_facility->facility_state = IOSTATE_WAITING;
- }
- else /* operation was either queued or failed*/
- {
- int err = GetLastError();
- if (ERROR_IO_PENDING == err)
- { /* operation queued */
- input_facility->facility_state = IOSTATE_QUEUED;
- }
- else
- { /* error occurred, let the rest of the elements finish */
- input_facility->path_open = FALSE;
- input_facility->facility_state = IOSTATE_FAILED;
- if (IOSTATE_WAITING == output_facility->facility_state)
- output_facility->path_open = FALSE;
-
- fprintf(stderr, "FATAL: Read from handle failed, allowing write to finish\n");
- }
- }
- }
- return TRUE;
-
- // We are queued and should check if the read has finished
- case IOSTATE_QUEUED:
- {
- // there was an operation going on already, check if that has completed now.
-
- if (GetOverlappedResult(input_facility->handle,
- &input_facility->overlapped,
- &input_facility->buffer_size,
- FALSE))
- { /* successful return for a queued operation */
- if (!ResetEvent(input_facility->overlapped.hEvent))
- return FALSE;
-
- fprintf(stderr, "DEBUG: tap read succeeded delayed\n");
-
- /* we successfully read something from the TAP and now need to
- * send it our via STDOUT. Is that possible at the moment? */
- if ((IOSTATE_READY == output_facility->facility_state ||
- IOSTATE_WAITING == output_facility->facility_state)
- && 0 < input_facility->buffer_size)
- { /* hand over this buffers content and apply message header for gnunet */
- hdr = (struct GNUNET_MessageHeader *)output_facility->buffer;
- size = input_facility->buffer_size + sizeof(struct GNUNET_MessageHeader);
-
- GNUNET_memcpy(output_facility->buffer + sizeof(struct GNUNET_MessageHeader),
- input_facility->buffer,
- input_facility->buffer_size);
-
- output_facility->buffer_size = size;
- hdr->size = htons(size);
- hdr->type = htons(GNUNET_MESSAGE_TYPE_VPN_HELPER);
- output_facility->facility_state = IOSTATE_READY;
- input_facility->facility_state = IOSTATE_READY;
- }
- else if (0 < input_facility->buffer_size)
- { /* If we have have read our buffer, wait for our write-partner*/
- input_facility->facility_state = IOSTATE_WAITING;
- // TODO: shall we attempt to fill our buffer or should we wait for our write-partner to finish?
- }
- }
- else
- { /* operation still pending/queued or failed? */
- int err = GetLastError();
- if ((ERROR_IO_INCOMPLETE != err) && (ERROR_IO_PENDING != err))
- { /* error occurred, let the rest of the elements finish */
- input_facility->path_open = FALSE;
- input_facility->facility_state = IOSTATE_FAILED;
- if (IOSTATE_WAITING == output_facility->facility_state)
- output_facility->path_open = FALSE;
- fprintf(stderr, "FATAL: Read from handle failed, allowing write to finish\n");
- }
- }
- }
- return TRUE;
-
- case IOSTATE_RESUME:
- hdr = (struct GNUNET_MessageHeader *)output_facility->buffer;
- size = input_facility->buffer_size + sizeof(struct GNUNET_MessageHeader);
-
- GNUNET_memcpy(output_facility->buffer + sizeof(struct GNUNET_MessageHeader),
- input_facility->buffer,
- input_facility->buffer_size);
-
- output_facility->buffer_size = size;
- hdr->size = htons(size);
- hdr->type = htons(GNUNET_MESSAGE_TYPE_VPN_HELPER);
- output_facility->facility_state = IOSTATE_READY;
- input_facility->facility_state = IOSTATE_READY;
- return TRUE;
-
- default:
- return TRUE;
- }
-}
-
-
-/**
- * Attempts to read off an input facility (tap or named pipe) in overlapped mode.
- *
- * 1.
- * If the input facility is in IOSTATE_READY, it will issue a new read operation to the
- * input handle. Then it goes into IOSTATE_QUEUED state.
- * In case the read succeeded instantly the input facility enters 3.
- *
- * 2.
- * If the input facility is in IOSTATE_QUEUED state, it will check if the queued read has finished already.
- * If it has finished, go to state 3.
- * If it has failed, set IOSTATE_FAILED
- *
- * 3.
- * If the facility is finished with ready
- * The read-buffer is copied to the output buffer, except for the GNUNET_MessageHeader.
- * The input facility enters state IOSTATE_READY
- * The output facility enters state IOSTATE_READY
- * If the output facility is in state IOSTATE_QUEUED, the input facility enters IOSTATE_WAITING
- *
- * IOSTATE_WAITING is reset by the output facility, once it has completed.
- *
- * @param input_facility input named pipe or file to work with.
- * @param output_facility output pipe or file to hand over data to.
- * @return false if an event reset was impossible (OS error), else true
- */
-static BOOL
-attempt_read_stdin(struct io_facility * input_facility,
- struct io_facility * output_facility)
-{
- struct GNUNET_MessageHeader * hdr;
-
- switch (input_facility->facility_state)
- {
- case IOSTATE_READY:
- {
- input_facility->buffer_size = 0;
-
-partial_read_iostate_ready:
- if (!ResetEvent(input_facility->overlapped.hEvent))
- return FALSE;
-
- /* Check how the task is handled */
- if (ReadFile(input_facility->handle,
- input_facility->buffer + input_facility->buffer_size,
- sizeof(input_facility->buffer) - input_facility->buffer_size,
- &input_facility->buffer_size_processed,
- &input_facility->overlapped))
- { /* async event processed immediately*/
- hdr = (struct GNUNET_MessageHeader *)input_facility->buffer;
-
- /* reset event manually*/
- if (!SetEvent(input_facility->overlapped.hEvent))
- return FALSE;
-
- fprintf(stderr, "DEBUG: stdin read succeeded immediately\n");
- input_facility->buffer_size += input_facility->buffer_size_processed;
-
- if (ntohs(hdr->type) != GNUNET_MESSAGE_TYPE_VPN_HELPER ||
- ntohs(hdr->size) > sizeof(input_facility->buffer))
- {
- fprintf(stderr, "WARNING: Protocol violation, got GNUnet Message type %h, size %h\n", ntohs(hdr->type), ntohs(hdr->size));
- input_facility->facility_state = IOSTATE_READY;
- return TRUE;
- }
- /* we got the a part of a packet */
- if (ntohs(hdr->size) > input_facility->buffer_size)
- goto partial_read_iostate_ready;
-
- /* have we read more than 0 bytes of payload? (sizeread > header)*/
- if (input_facility->buffer_size > sizeof(struct GNUNET_MessageHeader) &&
- ((IOSTATE_READY == output_facility->facility_state) ||
- (IOSTATE_WAITING == output_facility->facility_state)))
- { /* we successfully read something from the TAP and now need to
- * send it our via STDOUT. Is that possible at the moment? */
- /* hand over this buffers content and strip gnunet message header */
- GNUNET_memcpy(output_facility->buffer,
- input_facility->buffer + sizeof(struct GNUNET_MessageHeader),
- input_facility->buffer_size - sizeof(struct GNUNET_MessageHeader));
- output_facility->buffer_size = input_facility->buffer_size - sizeof(struct GNUNET_MessageHeader);
- output_facility->facility_state = IOSTATE_READY;
- input_facility->facility_state = IOSTATE_READY;
- }
- else if (input_facility->buffer_size > sizeof(struct GNUNET_MessageHeader))
- /* If we have have read our buffer, wait for our write-partner*/
- input_facility->facility_state = IOSTATE_WAITING;
- else /* we read nothing */
- input_facility->facility_state = IOSTATE_READY;
- }
- else /* operation was either queued or failed*/
- {
- int err = GetLastError();
- if (ERROR_IO_PENDING == err) /* operation queued */
- input_facility->facility_state = IOSTATE_QUEUED;
- else
- { /* error occurred, let the rest of the elements finish */
- input_facility->path_open = FALSE;
- input_facility->facility_state = IOSTATE_FAILED;
- if (IOSTATE_WAITING == output_facility->facility_state)
- output_facility->path_open = FALSE;
-
- fprintf(stderr, "FATAL: Read from handle failed, allowing write to finish\n");
- }
- }
- }
- return TRUE;
-
- // We are queued and should check if the read has finished
- case IOSTATE_QUEUED:
- {
- // there was an operation going on already, check if that has completed now.
- if (GetOverlappedResult(input_facility->handle,
- &input_facility->overlapped,
- &input_facility->buffer_size_processed,
- FALSE))
- { /* successful return for a queued operation */
- hdr = (struct GNUNET_MessageHeader *)input_facility->buffer;
-
- if (!ResetEvent(input_facility->overlapped.hEvent))
- return FALSE;
-
- fprintf(stderr, "DEBUG: stdin read succeeded delayed\n");
- input_facility->buffer_size += input_facility->buffer_size_processed;
-
- if ((ntohs(hdr->type) != GNUNET_MESSAGE_TYPE_VPN_HELPER) ||
- (ntohs(hdr->size) > sizeof(input_facility->buffer)))
- {
- fprintf(stderr, "WARNING: Protocol violation, got GNUnet Message type %h, size %h\n", ntohs(hdr->type), ntohs(hdr->size));
- input_facility->facility_state = IOSTATE_READY;
- return TRUE;
- }
- /* we got the a part of a packet */
- if (ntohs(hdr->size) > input_facility->buffer_size)
- ;
- goto partial_read_iostate_ready;
-
- /* we successfully read something from the TAP and now need to
- * send it our via STDOUT. Is that possible at the moment? */
- if ((IOSTATE_READY == output_facility->facility_state ||
- IOSTATE_WAITING == output_facility->facility_state)
- && input_facility->buffer_size > sizeof(struct GNUNET_MessageHeader))
- { /* hand over this buffers content and strip gnunet message header */
- GNUNET_memcpy(output_facility->buffer,
- input_facility->buffer + sizeof(struct GNUNET_MessageHeader),
- input_facility->buffer_size - sizeof(struct GNUNET_MessageHeader));
- output_facility->buffer_size = input_facility->buffer_size - sizeof(struct GNUNET_MessageHeader);
- output_facility->facility_state = IOSTATE_READY;
- input_facility->facility_state = IOSTATE_READY;
- }
- else if (input_facility->buffer_size > sizeof(struct GNUNET_MessageHeader))
- input_facility->facility_state = IOSTATE_WAITING;
- else
- input_facility->facility_state = IOSTATE_READY;
- }
- else
- { /* operation still pending/queued or failed? */
- int err = GetLastError();
- if ((ERROR_IO_INCOMPLETE != err) && (ERROR_IO_PENDING != err))
- { /* error occurred, let the rest of the elements finish */
- input_facility->path_open = FALSE;
- input_facility->facility_state = IOSTATE_FAILED;
- if (IOSTATE_WAITING == output_facility->facility_state)
- output_facility->path_open = FALSE;
- fprintf(stderr, "FATAL: Read from handle failed, allowing write to finish\n");
- }
- }
- }
- return TRUE;
-
- case IOSTATE_RESUME: /* Our buffer was filled already but our write facility was busy. */
- GNUNET_memcpy(output_facility->buffer,
- input_facility->buffer + sizeof(struct GNUNET_MessageHeader),
- input_facility->buffer_size - sizeof(struct GNUNET_MessageHeader));
- output_facility->buffer_size = input_facility->buffer_size - sizeof(struct GNUNET_MessageHeader);
- output_facility->facility_state = IOSTATE_READY;
- input_facility->facility_state = IOSTATE_READY;
- return TRUE;
-
- default:
- return TRUE;
- }
-}
-
-
-/**
- * Attempts to write to an output facility (tap or named pipe) in overlapped mode.
- *
- * TODO: high level description
- *
- * @param output_facility output pipe or file to hand over data to.
- * @param input_facility input named pipe or file to work with.
- * @return false if an event reset was impossible (OS error), else true
- */
-static BOOL
-attempt_write(struct io_facility * output_facility,
- struct io_facility * input_facility)
-{
- switch (output_facility->facility_state)
- {
- case IOSTATE_READY:
- output_facility->buffer_size_written = 0;
-
-continue_partial_write:
- if (!ResetEvent(output_facility->overlapped.hEvent))
- return FALSE;
-
- /* Check how the task was handled */
- if (WriteFile(output_facility->handle,
- output_facility->buffer + output_facility->buffer_size_written,
- output_facility->buffer_size - output_facility->buffer_size_written,
- &output_facility->buffer_size_processed,
- &output_facility->overlapped))
- {/* async event processed immediately*/
- fprintf(stderr, "DEBUG: write succeeded immediately\n");
- output_facility->buffer_size_written += output_facility->buffer_size_processed;
-
- /* reset event manually*/
- if (!SetEvent(output_facility->overlapped.hEvent))
- return FALSE;
-
- /* partial write */
- if (output_facility->buffer_size_written < output_facility->buffer_size)
- goto continue_partial_write;
-
- /* we are now waiting for our buffer to be filled*/
- output_facility->facility_state = IOSTATE_WAITING;
-
- /* we successfully wrote something and now need to reset our reader */
- if (IOSTATE_WAITING == input_facility->facility_state)
- input_facility->facility_state = IOSTATE_RESUME;
- else if (IOSTATE_FAILED == input_facility->facility_state)
- output_facility->path_open = FALSE;
- }
- else /* operation was either queued or failed*/
- {
- int err = GetLastError();
- if (ERROR_IO_PENDING == err)
- { /* operation queued */
- output_facility->facility_state = IOSTATE_QUEUED;
- }
- else
- { /* error occurred, close this path */
- output_facility->path_open = FALSE;
- output_facility->facility_state = IOSTATE_FAILED;
- fprintf(stderr, "FATAL: Write to handle failed, exiting\n");
- }
- }
- return TRUE;
-
- case IOSTATE_QUEUED:
- // there was an operation going on already, check if that has completed now.
-
- if (GetOverlappedResult(output_facility->handle,
- &output_facility->overlapped,
- &output_facility->buffer_size_processed,
- FALSE))
- {/* successful return for a queued operation */
- if (!ResetEvent(output_facility->overlapped.hEvent))
- return FALSE;
-
- fprintf(stderr, "DEBUG: write succeeded delayed\n");
- output_facility->buffer_size_written += output_facility->buffer_size_processed;
-
- /* partial write */
- if (output_facility->buffer_size_written < output_facility->buffer_size)
- goto continue_partial_write;
-
- /* we are now waiting for our buffer to be filled*/
- output_facility->facility_state = IOSTATE_WAITING;
-
- /* we successfully wrote something and now need to reset our reader */
- if (IOSTATE_WAITING == input_facility->facility_state)
- input_facility->facility_state = IOSTATE_RESUME;
- else if (IOSTATE_FAILED == input_facility->facility_state)
- output_facility->path_open = FALSE;
- }
- else
- { /* operation still pending/queued or failed? */
- int err = GetLastError();
- if ((ERROR_IO_INCOMPLETE != err) && (ERROR_IO_PENDING != err))
- { /* error occurred, close this path */
- output_facility->path_open = FALSE;
- output_facility->facility_state = IOSTATE_FAILED;
- fprintf(stderr, "FATAL: Write to handle failed, exiting\n");
- }
- }
-
- default:
- return TRUE;
- }
-}
-
-
-/**
- * Initialize a overlapped structure
- *
- * @param elem the element to initilize
- * @param initial_state the initial state for this instance
- * @param signaled if the hEvent created should default to signaled or not
- * @return true on success, else false
- */
-static BOOL
-initialize_io_facility(struct io_facility * elem,
- int initial_state,
- BOOL signaled)
-{
- elem->path_open = TRUE;
- elem->handle = INVALID_HANDLE_VALUE;
- elem->facility_state = initial_state;
- elem->buffer_size = 0;
- elem->overlapped.hEvent = CreateEvent(NULL, TRUE, signaled, NULL);
- if (NULL == elem->overlapped.hEvent)
- return FALSE;
-
- return TRUE;
-}
-
-
-/**
- * Start forwarding to and from the tunnel.
- *
- * @param tap_handle device handle for interacting with the Virtual interface
- */
-static void
-run(HANDLE tap_handle)
-{
- /* IO-Facility for reading from our virtual interface */
- struct io_facility tap_read;
- /* IO-Facility for writing to our virtual interface */
- struct io_facility tap_write;
- /* IO-Facility for reading from stdin */
- struct io_facility std_in;
- /* IO-Facility for writing to stdout */
- struct io_facility std_out;
-
- HANDLE parent_std_in_handle = GetStdHandle(STD_INPUT_HANDLE);
- HANDLE parent_std_out_handle = GetStdHandle(STD_OUTPUT_HANDLE);
-
- /* tun up: */
- /* we do this HERE and not beforehand (in init_tun()), in contrast to openvpn
- * to remove the need to flush the arp cache, handle DHCP and wrong IPs.
- *
- * DHCP and such are all features we will never use in gnunet afaik.
- * But for openvpn those are essential.
- */
- if ((privilege_testing) || (!tun_up(tap_handle)))
- goto teardown_final;
-
- /* Initialize our overlapped IO structures*/
- if (!(initialize_io_facility(&tap_read, IOSTATE_READY, FALSE)
- && initialize_io_facility(&tap_write, IOSTATE_WAITING, TRUE)
- && initialize_io_facility(&std_in, IOSTATE_READY, FALSE)
- && initialize_io_facility(&std_out, IOSTATE_WAITING, TRUE)))
- goto teardown_final;
-
- /* Handles for STDIN and STDOUT */
- tap_read.handle = tap_handle;
- tap_write.handle = tap_handle;
-
-#ifdef DEBUG_TO_CONSOLE
- /* Debug output to console STDIN/STDOUT*/
- std_in.handle = parent_std_in_handle;
- std_out.handle = parent_std_out_handle;
-#else
- fprintf(stderr, "DEBUG: reopening stdin/out for overlapped IO\n");
- /*
- * Find out the types of our handles.
- * This part is a problem, because in windows we need to handle files,
- * pipes and the console differently.
- */
- if ((FILE_TYPE_PIPE != GetFileType(parent_std_in_handle)) ||
- (FILE_TYPE_PIPE != GetFileType(parent_std_out_handle)))
- {
- fprintf(stderr, "ERROR: stdin/stdout must be named pipes\n");
- goto teardown;
- }
-
- std_in.handle = ReOpenFile(parent_std_in_handle,
- GENERIC_READ,
- FILE_SHARE_WRITE | FILE_SHARE_READ,
- FILE_FLAG_OVERLAPPED);
-
- if (INVALID_HANDLE_VALUE == std_in.handle)
- {
- fprintf(stderr, "FATAL: Could not reopen stdin for in overlapped mode, has to be a named pipe\n");
- goto teardown;
- }
-
- std_out.handle = ReOpenFile(parent_std_out_handle,
- GENERIC_WRITE,
- FILE_SHARE_READ,
- FILE_FLAG_OVERLAPPED);
-
- if (INVALID_HANDLE_VALUE == std_out.handle)
- {
- fprintf(stderr, "FATAL: Could not reopen stdout for in overlapped mode, has to be a named pipe\n");
- 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 */
- if (std_in.path_open && (!attempt_read_stdin(&std_in, &tap_write)))
- break;
-
- /* perform READ from tap if possible */
- if (tap_read.path_open && (!attempt_read_tap(&tap_read, &std_out)))
- break;
-
- /* perform WRITE to tap if possible */
- if (tap_write.path_open && (!attempt_write(&tap_write, &std_in)))
- break;
-
- /* perform WRITE to STDOUT if possible */
- if (std_out.path_open && (!attempt_write(&std_out, &tap_read)))
- break;
- }
-
- fprintf(stderr, "DEBUG: teardown initiated\n");
-teardown:
- CancelIo(tap_handle);
- CancelIo(std_in.handle);
- CancelIo(std_out.handle);
-teardown_final:
- CloseHandle(tap_handle);
-}
-
-
-/**
- * Open VPN tunnel interface.
- *
- * @param argc must be 6
- * @param argv 0: binary name (gnunet-helper-vpn)
- * [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)
-{
- char hwid[LINE_LEN];
- HANDLE handle;
- 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,
- "%s",
- "DEBUG: Running binary in privilege testing mode.");
- argv++;
- argc--;
- }
-
- if (6 != argc)
- {
- fprintf(stderr,
- "%s",
- "FATAL: must supply 5 arguments\nUsage:\ngnunet-helper-vpn [-d] <if name prefix> <address6 or \"-\"> <netbits6> <address4 or \"-\"> <netmask4>\n");
- return 1;
- }
-
- GNUNET_strlcpy(hwid, argv[1], sizeof(hwid));
-
- /*
- * We use our PID for finding/resolving the control-panel name of our virtual
- * device. PIDs are (of course) unique at runtime, thus we can safely use it
- * as additional hardware-id for our device.
- */
- snprintf(secondary_hwid, LINE_LEN / 2, "%s-%d",
- hwid,
- _getpid());
-
- if (INVALID_HANDLE_VALUE == (handle = init_tun()))
- {
- fprintf(stderr, "FATAL: could not initialize virtual-interface %s with IPv6 %s/%s and IPv4 %s/%s\n",
- hwid,
- argv[2],
- argv[3],
- argv[4],
- argv[5]);
- global_ret = -1;
- goto cleanup;
- }
-
- fprintf(stderr, "DEBUG: Setting IPs, if needed\n");
- if (0 != strcmp(argv[2], "-"))
- {
- const char *address = argv[2];
- long prefix_len = atol(argv[3]);
-
- if ((prefix_len < 1) || (prefix_len > 127))
- {
- fprintf(stderr, "FATAL: ipv6 prefix_len out of range\n");
- global_ret = -1;
- goto cleanup;
- }
-
- fprintf(stderr, "DEBUG: Setting IP6 address: %s/%d\n", address, prefix_len);
- if (0 != (global_ret = set_address6(address, prefix_len)))
- goto cleanup;
-
- have_ip6 = TRUE;
- }
-
- if (0 != strcmp(argv[4], "-"))
- {
- const char *address = argv[4];
- const char *mask = argv[5];
-
- fprintf(stderr, "DEBUG: Setting IP4 address: %s/%s\n", address, mask);
- if (0 != (global_ret = set_address4(address, mask)))
- goto cleanup;
-
- have_ip4 = TRUE;
- }
-
- run(handle);
-cleanup:
-
- if (have_ip4)
- {
- const char *address = argv[4];
- fprintf(stderr, "DEBUG: Removing IP4 address\n");
- remove_address4(address);
- }
- if (have_ip6)
- {
- const char *address = argv[2];
- fprintf(stderr, "DEBUG: Removing IP6 address\n");
- remove_address6(address);
- }
-
- fprintf(stderr, "DEBUG: removing interface\n");
- remove_interface();
- fprintf(stderr, "DEBUG: graceful exit completed\n");
-
- return global_ret;
-}
diff --git a/src/zonemaster/Makefile.am b/src/zonemaster/Makefile.am
index b655b9ef3..3d248efd8 100644
--- a/src/zonemaster/Makefile.am
+++ b/src/zonemaster/Makefile.am
@@ -10,10 +10,6 @@ libexecdir= $(pkglibdir)/libexec/
pkgcfg_DATA = \
zonemaster.conf
-if MINGW
- WINFLAGS = -Wl,--no-undefined -Wl,--export-all-symbols
-endif
-
if USE_COVERAGE
AM_CFLAGS = --coverage -O0
XLIBS = -lgcov