aboutsummaryrefslogtreecommitdiff
path: root/src/vpn
diff options
context:
space:
mode:
authorChristian Fuchs <christian.fuchs@cfuchs.net>2012-12-09 23:22:13 +0000
committerChristian Fuchs <christian.fuchs@cfuchs.net>2012-12-09 23:22:13 +0000
commite9c426eb55c28a436aee3a2404e0a3181257b674 (patch)
tree9f14e8f8b11001592d3bf7eff031e9947087d35a /src/vpn
parent13beed47313158524d3192d5db19518927e054a6 (diff)
downloadgnunet-e9c426eb55c28a436aee3a2404e0a3181257b674.tar.gz
gnunet-e9c426eb55c28a436aee3a2404e0a3181257b674.zip
added unique additional hwid entry to allow us to find our individual
virtual interface again. Needed, because netsh requires us to resolve the devices name as string, which can not be derived off the deviceinfoset directly. we are now using the handed over devicename + our PID the result looks something like this: gnunet-vpn13381
Diffstat (limited to 'src/vpn')
-rw-r--r--src/vpn/gnunet-helper-vpn-windows.c70
1 files changed, 48 insertions, 22 deletions
diff --git a/src/vpn/gnunet-helper-vpn-windows.c b/src/vpn/gnunet-helper-vpn-windows.c
index c607d52e6..cee450f45 100644
--- a/src/vpn/gnunet-helper-vpn-windows.c
+++ b/src/vpn/gnunet-helper-vpn-windows.c
@@ -70,6 +70,12 @@
70 */ 70 */
71#define HARDWARE_ID _T("TAP0901") 71#define HARDWARE_ID _T("TAP0901")
72 72
73/*
74 * Our local process' PID. Used for creating a sufficiently unique additional
75 * hardware ID for our device.
76 */
77static TCHAR secondary_hwid[LINE_LEN / 2];
78
73/** 79/**
74 * This is our own local instance of a virtual network interface 80 * This is our own local instance of a virtual network interface
75 * It is (somewhat) equivalent to using tun/tap in unixoid systems 81 * It is (somewhat) equivalent to using tun/tap in unixoid systems
@@ -200,17 +206,10 @@ setup_interface ()
200 * We do not directly input all the props here, because openvpn will update 206 * We do not directly input all the props here, because openvpn will update
201 * these details over time. 207 * these details over time.
202 */ 208 */
203 TCHAR InfFilePath[MAX_PATH]; 209 TCHAR inf_file_path[MAX_PATH];
204 TCHAR hwIdList[LINE_LEN + 4]; 210 TCHAR hwidlist[LINE_LEN + 4];
211 int str_lenth = 0;
205 212
206 /**
207 * Locate the inf-file, we need to store it somewhere where the system can
208 * find it. A good choice would be CWD/PDW or %WINDIR$\system32\
209 *
210 * TODO: Find a more sane way to do this!
211 * TODO: How about win64 in the future?
212 */
213 GetFullPathName (INF_FILE, MAX_PATH, InfFilePath, NULL);
214 213
215 /** 214 /**
216 * Set the device's hardware ID and add it to a list. 215 * Set the device's hardware ID and add it to a list.
@@ -219,12 +218,30 @@ setup_interface ()
219 * TODO: Currently we just use TAP0901 as HWID, 218 * TODO: Currently we just use TAP0901 as HWID,
220 * but we might want to add additional information 219 * but we might want to add additional information
221 */ 220 */
222 strncpy (hwIdList, HARDWARE_ID, LINE_LEN); 221 strncpy (hwidlist, HARDWARE_ID, LINE_LEN);
222 /**
223 * this is kind of over-complicated, but allows keeps things independent of
224 * how the openvpn-hwid is actually stored.
225 *
226 * A HWID list is double-\0 terminated and \0 separated
227 */
228 str_lenth = strlen (hwidlist) + 1 ;
229 hwidlist[str_lenth] = _T("\0");
230 strncpy (&hwidlist[str_lenth], secondary_hwid, LINE_LEN - str_lenth);
231
232 /**
233 * Locate the inf-file, we need to store it somewhere where the system can
234 * find it. A good choice would be CWD/PDW or %WINDIR$\system32\
235 *
236 * TODO: How about win64 in the future?
237 * We need to use a different driver for amd64/i386 !
238 */
239 GetFullPathName (INF_FILE, MAX_PATH, inf_file_path, NULL);
223 240
224 /** 241 /**
225 * Bootstrap our device info using the drivers inf-file 242 * Bootstrap our device info using the drivers inf-file
226 */ 243 */
227 if (!SetupDiGetINFClass (InfFilePath, 244 if (!SetupDiGetINFClass (inf_file_path,
228 &guid, 245 &guid,
229 class, sizeof (class) / sizeof (TCHAR), 246 class, sizeof (class) / sizeof (TCHAR),
230 NULL)) 247 NULL))
@@ -236,7 +253,7 @@ setup_interface ()
236 */ 253 */
237 DeviceInfo = SetupDiCreateDeviceInfoList (&guid, NULL); 254 DeviceInfo = SetupDiCreateDeviceInfoList (&guid, NULL);
238 if (DeviceInfo == INVALID_HANDLE_VALUE) 255 if (DeviceInfo == INVALID_HANDLE_VALUE)
239 goto cleanup; 256 return FALSE;
240 257
241 DeviceNode.cbSize = sizeof (SP_DEVINFO_DATA); 258 DeviceNode.cbSize = sizeof (SP_DEVINFO_DATA);
242 if (!SetupDiCreateDeviceInfo (DeviceInfo, 259 if (!SetupDiCreateDeviceInfo (DeviceInfo,
@@ -246,15 +263,15 @@ setup_interface ()
246 NULL, 263 NULL,
247 DICD_GENERATE_ID, 264 DICD_GENERATE_ID,
248 &DeviceNode)) 265 &DeviceNode))
249 goto cleanup; 266 return FALSE;
250 267
251 /* Deploy all the information collected into the registry */ 268 /* Deploy all the information collected into the registry */
252 if (!SetupDiSetDeviceRegistryProperty (DeviceInfo, 269 if (!SetupDiSetDeviceRegistryProperty (DeviceInfo,
253 &DeviceNode, 270 &DeviceNode,
254 SPDRP_HARDWAREID, 271 SPDRP_HARDWAREID,
255 (LPBYTE) hwIdList, 272 (LPBYTE) hwidlist,
256 (lstrlen (hwIdList) + 2) * sizeof (TCHAR))) 273 (lstrlen (hwidlist) + 2) * sizeof (TCHAR)))
257 goto cleanup; 274 return FALSE;
258 275
259 /* Install our new class(=device) into the system */ 276 /* Install our new class(=device) into the system */
260 if (SetupDiCallClassInstaller (DIF_REGISTERDEVICE, 277 if (SetupDiCallClassInstaller (DIF_REGISTERDEVICE,
@@ -262,11 +279,7 @@ setup_interface ()
262 &DeviceNode)) 279 &DeviceNode))
263 return TRUE; 280 return TRUE;
264 281
265 //disabled for debug-reasons...
266cleanup:
267// GNUNET_free(DeviceInfo);
268 return FALSE; 282 return FALSE;
269
270} 283}
271 284
272 285
@@ -304,6 +317,9 @@ remove_interface ()
304 DeviceInfo, 317 DeviceInfo,
305 (PSP_DEVINFO_DATA) &DeviceNode)) 318 (PSP_DEVINFO_DATA) &DeviceNode))
306 return FALSE; 319 return FALSE;
320
321 SetupDiDestroyDeviceInfoList(DeviceInfo);
322
307 return TRUE; 323 return TRUE;
308} 324}
309 325
@@ -377,9 +393,10 @@ int
377main (int argc, char **argv) 393main (int argc, char **argv)
378{ 394{
379 TCHAR hwid[LINE_LEN]; 395 TCHAR hwid[LINE_LEN];
396 TCHAR pid_as_string[LINE_LEN / 4];
380 int fd_tun; 397 int fd_tun;
381 int global_ret; 398 int global_ret;
382 399
383 if (6 != argc) 400 if (6 != argc)
384 { 401 {
385 fprintf (stderr, "Fatal: must supply 5 arguments!\n"); 402 fprintf (stderr, "Fatal: must supply 5 arguments!\n");
@@ -388,6 +405,15 @@ main (int argc, char **argv)
388 405
389 strncpy (hwid, argv[1], LINE_LEN); 406 strncpy (hwid, argv[1], LINE_LEN);
390 hwid[LINE_LEN - 1] = _T('\0'); 407 hwid[LINE_LEN - 1] = _T('\0');
408
409 /*
410 * We use our PID for finding/resolving the control-panel name of our virtual
411 * device. PIDs are (of course) unique at runtime, thus we can safely use it
412 * as additional hardware-id for our device.
413 */
414 _itot(_getpid(), pid_as_string, 10);
415 strncpy (secondary_hwid, hwid, LINE_LEN);
416 strncat (secondary_hwid, pid_as_string, LINE_LEN);
391 417
392 if (-1 == (fd_tun = init_tun (hwid))) 418 if (-1 == (fd_tun = init_tun (hwid)))
393 { 419 {