diff options
author | Christian Fuchs <christian.fuchs@cfuchs.net> | 2012-11-16 09:03:54 +0000 |
---|---|---|
committer | Christian Fuchs <christian.fuchs@cfuchs.net> | 2012-11-16 09:03:54 +0000 |
commit | 934db0fcddb6c3fb793e1995cb3441b22945809a (patch) | |
tree | 2733162eb5d053e34b3acf653b35b9175df4dcea /src/vpn | |
parent | 246cd58943ccff6dd50bb10d5e01ea8ba4e2e0f5 (diff) | |
download | gnunet-934db0fcddb6c3fb793e1995cb3441b22945809a.tar.gz gnunet-934db0fcddb6c3fb793e1995cb3441b22945809a.zip |
- added vpn helper stub for win32 builds
- modified vpn-makefile definitions to process gnunet-helper-vpn-windows
instead of the regular one when using mingw as toolchain
Diffstat (limited to 'src/vpn')
-rw-r--r-- | src/vpn/Makefile.am | 11 | ||||
-rw-r--r-- | src/vpn/gnunet-helper-vpn-windows.c | 282 |
2 files changed, 290 insertions, 3 deletions
diff --git a/src/vpn/Makefile.am b/src/vpn/Makefile.am index 71601383e..b80be7749 100644 --- a/src/vpn/Makefile.am +++ b/src/vpn/Makefile.am | |||
@@ -2,6 +2,7 @@ INCLUDES = -I$(top_srcdir)/src/include | |||
2 | 2 | ||
3 | if MINGW | 3 | if MINGW |
4 | WINFLAGS = -Wl,--no-undefined -Wl,--export-all-symbols | 4 | WINFLAGS = -Wl,--no-undefined -Wl,--export-all-symbols |
5 | VPNBIN = gnunet-helper-vpn | ||
5 | endif | 6 | endif |
6 | 7 | ||
7 | if USE_COVERAGE | 8 | if USE_COVERAGE |
@@ -37,9 +38,13 @@ libexec_PROGRAMS = \ | |||
37 | bin_PROGRAMS = \ | 38 | bin_PROGRAMS = \ |
38 | gnunet-vpn | 39 | gnunet-vpn |
39 | 40 | ||
40 | gnunet_helper_vpn_SOURCES = \ | 41 | if MINGW |
41 | gnunet-helper-vpn.c | 42 | gnunet_helper_vpn_SOURCES = \ |
42 | 43 | gnunet-helper-vpn-windows.c | |
44 | else | ||
45 | gnunet_helper_vpn_SOURCES = \ | ||
46 | gnunet-helper-vpn.c | ||
47 | endif | ||
43 | gnunet_service_vpn_SOURCES = \ | 48 | gnunet_service_vpn_SOURCES = \ |
44 | gnunet-service-vpn.c | 49 | gnunet-service-vpn.c |
45 | gnunet_service_vpn_LDADD = \ | 50 | gnunet_service_vpn_LDADD = \ |
diff --git a/src/vpn/gnunet-helper-vpn-windows.c b/src/vpn/gnunet-helper-vpn-windows.c new file mode 100644 index 000000000..8ac68132e --- /dev/null +++ b/src/vpn/gnunet-helper-vpn-windows.c | |||
@@ -0,0 +1,282 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet. | ||
3 | (C) 2010, 2012 Christian Grothoff | ||
4 | |||
5 | GNUnet is free software; you can redistribute it and/or modify | ||
6 | it under the terms of the GNU General Public License as published | ||
7 | by the Free Software Foundation; either version 3, or (at your | ||
8 | option) any later version. | ||
9 | |||
10 | GNUnet is distributed in the hope that it will be useful, but | ||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
13 | General Public License for more details. | ||
14 | |||
15 | You should have received a copy of the GNU General Public License | ||
16 | along with GNUnet; see the file COPYING. If not, write to the | ||
17 | Free Software Foundation, Inc., 59 Temple Place - Suite 330, | ||
18 | Boston, MA 02111-1307, USA. | ||
19 | */ | ||
20 | |||
21 | /** | ||
22 | * @file vpn/gnunet-helper-vpn-windows.c | ||
23 | * @brief the helper for the VPN service in win32 builds. | ||
24 | * Opens a virtual network-interface, sends data received on the if to stdout, | ||
25 | * sends data received on stdin to the interface | ||
26 | * @author Christian M. Fuchs | ||
27 | * | ||
28 | * The following list of people have reviewed this code and considered | ||
29 | * it safe since the last modification (if you reviewed it, please | ||
30 | * have your name added to the list): | ||
31 | * | ||
32 | */ | ||
33 | |||
34 | #include "platform.h" | ||
35 | |||
36 | /** | ||
37 | * Need 'struct GNUNET_MessageHeader'. | ||
38 | */ | ||
39 | #include "gnunet_common.h" | ||
40 | |||
41 | /** | ||
42 | * Need VPN message types. | ||
43 | */ | ||
44 | #include "gnunet_protocols.h" | ||
45 | |||
46 | /** | ||
47 | * Should we print (interesting|debug) messages that can happen during | ||
48 | * normal operation? | ||
49 | */ | ||
50 | #define DEBUG GNUNET_NO | ||
51 | |||
52 | /** | ||
53 | * Maximum size of a GNUnet message (GNUNET_SERVER_MAX_MESSAGE_SIZE) | ||
54 | */ | ||
55 | #define MAX_SIZE 65536 | ||
56 | |||
57 | /** | ||
58 | * Creates a tun-interface called dev; | ||
59 | * | ||
60 | * @param dev is asumed to point to a char[IFNAMSIZ] | ||
61 | * if *dev == '\\0', uses the name supplied by the kernel; | ||
62 | * @return the fd to the tun or -1 on error | ||
63 | */ | ||
64 | static int | ||
65 | init_tun (char *dev) | ||
66 | { | ||
67 | int fd; | ||
68 | |||
69 | if (NULL == dev) | ||
70 | { | ||
71 | errno = EINVAL; | ||
72 | return -1; | ||
73 | } | ||
74 | |||
75 | /* Hello, I am a stub function! I did my job, yay me! */ | ||
76 | |||
77 | return fd; | ||
78 | } | ||
79 | |||
80 | |||
81 | /** | ||
82 | * @brief Sets the IPv6-Address given in address on the interface dev | ||
83 | * | ||
84 | * @param dev the interface to configure | ||
85 | * @param address the IPv6-Address | ||
86 | * @param prefix_len the length of the network-prefix | ||
87 | */ | ||
88 | static void | ||
89 | set_address6 (const char *dev, const char *address, unsigned long prefix_len) | ||
90 | { | ||
91 | int fd=0; | ||
92 | |||
93 | /* | ||
94 | * parse the new address | ||
95 | */ | ||
96 | |||
97 | /* | ||
98 | * Get the index of the if | ||
99 | */ | ||
100 | |||
101 | /* | ||
102 | * Set the address | ||
103 | */ | ||
104 | |||
105 | /* | ||
106 | * Get the flags | ||
107 | */ | ||
108 | |||
109 | |||
110 | /* | ||
111 | * Add the UP and RUNNING flags | ||
112 | */ | ||
113 | |||
114 | |||
115 | if (0 != close (fd)) | ||
116 | { | ||
117 | fprintf (stderr, "close failed: %s\n", strerror (errno)); | ||
118 | exit (1); | ||
119 | } | ||
120 | } | ||
121 | |||
122 | |||
123 | /** | ||
124 | * @brief Sets the IPv4-Address given in address on the interface dev | ||
125 | * | ||
126 | * @param dev the interface to configure | ||
127 | * @param address the IPv4-Address | ||
128 | * @param mask the netmask | ||
129 | */ | ||
130 | static void | ||
131 | set_address4 (const char *dev, const char *address, const char *mask) | ||
132 | { | ||
133 | int fd=0; | ||
134 | |||
135 | /* | ||
136 | * Parse the address | ||
137 | */ | ||
138 | |||
139 | /* | ||
140 | * Set the address | ||
141 | */ | ||
142 | |||
143 | /* | ||
144 | * Parse the netmask | ||
145 | */ | ||
146 | |||
147 | |||
148 | /* | ||
149 | * Set the netmask | ||
150 | */ | ||
151 | |||
152 | |||
153 | /* | ||
154 | * Get the flags | ||
155 | */ | ||
156 | |||
157 | |||
158 | /* | ||
159 | * Add the UP and RUNNING flags | ||
160 | */ | ||
161 | |||
162 | |||
163 | if (0 != close (fd)) | ||
164 | { | ||
165 | fprintf (stderr, "close failed: %s\n", strerror (errno)); | ||
166 | (void) close (fd); | ||
167 | exit (1); | ||
168 | } | ||
169 | } | ||
170 | |||
171 | |||
172 | /** | ||
173 | * Start forwarding to and from the tunnel. | ||
174 | * | ||
175 | * @param fd_tun tunnel FD | ||
176 | */ | ||
177 | static void | ||
178 | run (int fd_tun) | ||
179 | { | ||
180 | /* | ||
181 | * The buffer filled by reading from fd_tun | ||
182 | */ | ||
183 | unsigned char buftun[MAX_SIZE]; | ||
184 | ssize_t buftun_size = 0; | ||
185 | unsigned char *buftun_read = NULL; | ||
186 | |||
187 | /* | ||
188 | * The buffer filled by reading from stdin | ||
189 | */ | ||
190 | unsigned char bufin[MAX_SIZE]; | ||
191 | ssize_t bufin_size = 0; | ||
192 | size_t bufin_rpos = 0; | ||
193 | unsigned char *bufin_read = NULL; | ||
194 | /* Hello, I am a stub function! I did my job, yay me! */ | ||
195 | } | ||
196 | |||
197 | |||
198 | /** | ||
199 | * Open VPN tunnel interface. | ||
200 | * | ||
201 | * @param argc must be 6 | ||
202 | * @param argv 0: binary name (gnunet-helper-vpn) | ||
203 | * 1: tunnel interface name (gnunet-vpn) | ||
204 | * 2: IPv6 address (::1), "-" to disable | ||
205 | * 3: IPv6 netmask length in bits (64), ignored if #2 is "-" | ||
206 | * 4: IPv4 address (1.2.3.4), "-" to disable | ||
207 | * 5: IPv4 netmask (255.255.0.0), ignored if #4 is "-" | ||
208 | */ | ||
209 | int | ||
210 | main (int argc, char **argv) | ||
211 | { | ||
212 | //char dev[IFNAMSIZ]; | ||
213 | int fd_tun; | ||
214 | int global_ret; | ||
215 | |||
216 | if (6 != argc) | ||
217 | { | ||
218 | fprintf (stderr, "Fatal: must supply 5 arguments!\n"); | ||
219 | return 1; | ||
220 | } | ||
221 | |||
222 | /* | ||
223 | * strncpy (dev, argv[1], IFNAMSIZ); | ||
224 | * dev[IFNAMSIZ - 1] = '\0'; | ||
225 | */ | ||
226 | /* if (-1 == (fd_tun = init_tun (dev))) | ||
227 | { | ||
228 | fprintf (stderr, "Fatal: could not initialize tun-interface with IPv6 %s/%s and IPv4 %s/%s\n", | ||
229 | dev, | ||
230 | argv[2], | ||
231 | argv[3], | ||
232 | argv[4], | ||
233 | argv[5]); | ||
234 | return 1; | ||
235 | } | ||
236 | */ | ||
237 | |||
238 | if (0 != strcmp (argv[2], "-")) | ||
239 | { | ||
240 | const char *address = argv[2]; | ||
241 | long prefix_len = atol (argv[3]); | ||
242 | |||
243 | if ((prefix_len < 1) || (prefix_len > 127)) | ||
244 | { | ||
245 | fprintf (stderr, "Fatal: prefix_len out of range\n"); | ||
246 | return 1; | ||
247 | } | ||
248 | |||
249 | //set_address6 (dev, address, prefix_len); | ||
250 | } | ||
251 | |||
252 | if (0 != strcmp (argv[4], "-")) | ||
253 | { | ||
254 | const char *address = argv[4]; | ||
255 | const char *mask = argv[5]; | ||
256 | |||
257 | set_address4 (NULL, address, mask); | ||
258 | } | ||
259 | |||
260 | /* | ||
261 | uid_t uid = getuid (); | ||
262 | if (0 != setresuid (uid, uid, uid)) | ||
263 | { | ||
264 | fprintf (stderr, "Failed to setresuid: %s\n", strerror (errno)); | ||
265 | global_ret = 2; | ||
266 | goto cleanup; | ||
267 | } | ||
268 | */ | ||
269 | |||
270 | /*if (SIG_ERR == signal (SIGPIPE, SIG_IGN)) | ||
271 | { | ||
272 | fprintf (stderr, "Failed to protect against SIGPIPE: %s\n", | ||
273 | strerror (errno)); | ||
274 | // no exit, we might as well die with SIGPIPE should it ever happen | ||
275 | } | ||
276 | */ | ||
277 | //run (fd_tun); | ||
278 | global_ret = 0; | ||
279 | cleanup: | ||
280 | //close (fd_tun); | ||
281 | return global_ret; | ||
282 | } | ||