aboutsummaryrefslogtreecommitdiff
path: root/src/vpn
diff options
context:
space:
mode:
authorChristian Fuchs <christian.fuchs@cfuchs.net>2012-12-29 20:20:53 +0000
committerChristian Fuchs <christian.fuchs@cfuchs.net>2012-12-29 20:20:53 +0000
commitf3eca31df25d50ebe32c5d38f31cc7a62e62914d (patch)
tree2572b2abca188b45b5644a2e68fa0c44395f7c21 /src/vpn
parent95b5cab4c81ce029c85be0266e6cbf0dbfc3d381 (diff)
downloadgnunet-f3eca31df25d50ebe32c5d38f31cc7a62e62914d.tar.gz
gnunet-f3eca31df25d50ebe32c5d38f31cc7a62e62914d.zip
reworked vpn-helper to now use regular(!) char, instead of wchar,
according to recommendations found in the C/C++-specs(wchar != unicode support, but may break compiler compatibility).
Diffstat (limited to 'src/vpn')
-rw-r--r--src/vpn/gnunet-helper-vpn-windows.c242
1 files changed, 149 insertions, 93 deletions
diff --git a/src/vpn/gnunet-helper-vpn-windows.c b/src/vpn/gnunet-helper-vpn-windows.c
index 73b0eec2b..bf5585204 100644
--- a/src/vpn/gnunet-helper-vpn-windows.c
+++ b/src/vpn/gnunet-helper-vpn-windows.c
@@ -32,11 +32,11 @@
32 */ 32 */
33 33
34#include <stdio.h> 34#include <stdio.h>
35#include <tchar.h>
36#include <windows.h> 35#include <windows.h>
37#include <setupapi.h> 36#include <setupapi.h>
38#include <ddk/cfgmgr32.h> 37#include <ddk/cfgmgr32.h>
39#include "platform.h" 38#include "platform.h"
39#include <Winsock2.h>
40 40
41/** 41/**
42 * Need 'struct GNUNET_MessageHeader'. 42 * Need 'struct GNUNET_MessageHeader'.
@@ -63,13 +63,13 @@
63 * Name or Path+Name of our driver in Unicode. 63 * Name or Path+Name of our driver in Unicode.
64 * The .sys and .cat files HAVE to be in the same location as this file! 64 * The .sys and .cat files HAVE to be in the same location as this file!
65 */ 65 */
66#define INF_FILE _T("tapw32.inf") 66#define INF_FILE "tapw32.inf"
67 67
68/** 68/**
69 * Hardware ID used in the inf-file. 69 * Hardware ID used in the inf-file.
70 * This might change over time, as openvpn advances their driver 70 * This might change over time, as openvpn advances their driver
71 */ 71 */
72#define HARDWARE_ID _T("TAP0901") 72#define HARDWARE_ID "TAP0901"
73 73
74/** 74/**
75 * Location of the network interface list resides in registry. 75 * Location of the network interface list resides in registry.
@@ -78,25 +78,16 @@
78#define INTERFACE_REGISTRY_LOCATION "SYSTEM\\CurrentControlSet\\Control\\Network\\{4D36E972-E325-11CE-BFC1-08002BE10318}" 78#define INTERFACE_REGISTRY_LOCATION "SYSTEM\\CurrentControlSet\\Control\\Network\\{4D36E972-E325-11CE-BFC1-08002BE10318}"
79 79
80/** 80/**
81 * TCHAR wrappers, which is missing in mingw's includes:
82 */
83#ifdef _UNICODE
84#define _tpopen _wpopen
85#else
86#define _tpopen _popen
87#endif
88
89/**
90 * Our local process' PID. Used for creating a sufficiently unique additional 81 * Our local process' PID. Used for creating a sufficiently unique additional
91 * hardware ID for our device. 82 * hardware ID for our device.
92 */ 83 */
93static TCHAR secondary_hwid[LINE_LEN / 2]; 84static char secondary_hwid[LINE_LEN / 2];
94 85
95/** 86/**
96 * Device's visible Name, used to identify a network device in netsh. 87 * Device's visible Name, used to identify a network device in netsh.
97 * eg: "Local Area Connection 9" 88 * eg: "Local Area Connection 9"
98 */ 89 */
99static TCHAR device_visible_name[256]; 90static char device_visible_name[256];
100 91
101/** 92/**
102 * This is our own local instance of a virtual network interface 93 * This is our own local instance of a virtual network interface
@@ -117,7 +108,7 @@ static SP_DEVINFO_DATA DeviceNode;
117/** 108/**
118 * Class-tag of our virtual device 109 * Class-tag of our virtual device
119 */ 110 */
120static TCHAR class[128]; 111static char class[128];
121 112
122/** 113/**
123 * GUID of our virtual device in the form of 114 * GUID of our virtual device in the form of
@@ -125,6 +116,48 @@ static TCHAR class[128];
125 */ 116 */
126static GUID guid; 117static GUID guid;
127 118
119
120/**
121 * inet_pton() wrapper for WSAStringToAddress()
122 *
123 * this is needed as long as we support WinXP, because only Vista+ support
124 * inet_pton at all, and mingw does not yet offer inet_pton/ntop at all
125 *
126 * @param af - IN - the aftype this address is supposed to be (v4/v6)
127 * @param src - IN - the presentation form of the address
128 * @param dst - OUT - the numerical form of the address
129 * @return 0 on success, 1 on failure
130 */
131#if WINVER >= 0x0600
132int inet_pton (int af, const char *src, void *dst);
133#else
134int
135inet_pton (int af, const char *src, void *dst)
136{
137 struct sockaddr_storage addr;
138 int size = sizeof (addr);
139 char local_copy[INET6_ADDRSTRLEN + 1];
140
141 ZeroMemory (&addr, sizeof (addr));
142 /* stupid non-const API */
143 strncpy (local_copy, src, INET6_ADDRSTRLEN + 1);
144 local_copy[INET6_ADDRSTRLEN] = 0;
145
146 if (WSAStringToAddressA (local_copy, af, NULL, (struct sockaddr *) &addr, &size) == 0)
147 {
148 switch (af)
149 {
150 case AF_INET:
151 *(struct in_addr *) dst = ((struct sockaddr_in *) &addr)->sin_addr;
152 return 1;
153 case AF_INET6:
154 *(struct in6_addr *) dst = ((struct sockaddr_in6 *) &addr)->sin6_addr;
155 return 1;
156 }
157 }
158 return 0;
159}
160#endif
128/** 161/**
129 * Wrapper for executing a shellcommand in windows. 162 * Wrapper for executing a shellcommand in windows.
130 * 163 *
@@ -134,21 +167,21 @@ static GUID guid;
134 * * EPIPE (could not read STDOUT) 167 * * EPIPE (could not read STDOUT)
135 */ 168 */
136static int 169static int
137execute_shellcommand (TCHAR * command) 170execute_shellcommand (char * command)
138{ 171{
139 FILE *pipe; 172 FILE *pipe;
140 173
141 if (NULL == command || 174 if (NULL == command ||
142 NULL == (pipe = _tpopen (command, "rt"))) 175 NULL == (pipe = _popen (command, "rt")))
143 return EINVAL; 176 return EINVAL;
144 177
145#ifdef TESTING 178#ifdef TESTING
146 { 179 {
147 TCHAR output[LINE_LEN]; 180 char output[LINE_LEN];
148 181
149 _tprintf (_T ("executed command: %s"), command); 182 printf ("executed command: %s", command);
150 while (NULL != _fgetts (output, sizeof (output), pipe)) 183 while (NULL != fgets (output, sizeof (output), pipe))
151 _tprintf (output); 184 printf (output);
152 } 185 }
153#endif 186#endif
154 187
@@ -165,19 +198,29 @@ execute_shellcommand (TCHAR * command)
165 * @param prefix_len the length of the network-prefix 198 * @param prefix_len the length of the network-prefix
166 */ 199 */
167static void 200static void
168set_address6 (const TCHAR *address, unsigned long prefix_len) 201set_address6 (const char *address, unsigned long prefix_len)
169{ 202{
170 int ret = EINVAL; 203 int ret = EINVAL;
171 TCHAR command[LINE_LEN]; 204 char command[LINE_LEN];
205 struct sockaddr_in6 sa6;
172 206
173 /* TODO: Check if address makes sense? */ 207 /*
208 * parse the new address
209 */
210 memset (&sa6, 0, sizeof (struct sockaddr_in6));
211 sa6.sin6_family = AF_INET6;
212 if (1 != inet_pton (AF_INET6, address, &sa6.sin6_addr.s6_addr))
213 {
214 fprintf (stderr, "Failed to parse address `%s': %s\n", address,
215 strerror (errno));
216 exit (1);
217 }
174 218
175 /* 219 /*
176 * prepare the command 220 * prepare the command
177 */ 221 */
178 222 snprintf (command, LINE_LEN,
179 _sntprintf (command, LINE_LEN, 223 "netsh interface ipv6 add address \"%s\" %s/%d",
180 _T ("netsh interface ipv6 add address \"%s\" %s/%d"),
181 device_visible_name, address, prefix_len); 224 device_visible_name, address, prefix_len);
182 /* 225 /*
183 * Set the address 226 * Set the address
@@ -187,7 +230,7 @@ set_address6 (const TCHAR *address, unsigned long prefix_len)
187 /* Did it work?*/ 230 /* Did it work?*/
188 if (0 != ret) 231 if (0 != ret)
189 { 232 {
190 _ftprintf (stderr, _T ("Setting IPv6 address failed: %s\n"), strerror (ret)); 233 fprintf (stderr, "Setting IPv6 address failed: %s\n", strerror (ret));
191 exit (1); // FIXME: return error code, shut down interface / unload driver 234 exit (1); // FIXME: return error code, shut down interface / unload driver
192 } 235 }
193} 236}
@@ -203,15 +246,26 @@ static void
203set_address4 (const char *address, const char *mask) 246set_address4 (const char *address, const char *mask)
204{ 247{
205 int ret = EINVAL; 248 int ret = EINVAL;
206 TCHAR command[LINE_LEN]; 249 char command[LINE_LEN];
207 250
208 /* TODO: Check if address & prefix_len make sense*/ 251 struct sockaddr_in addr;
252 addr.sin_family = AF_INET;
253
254 /*
255 * Parse the address
256 */
257 if (1 != inet_pton (AF_INET, address, &addr.sin_addr.s_addr))
258 {
259 fprintf (stderr, "Failed to parse address `%s': %s\n", address,
260 strerror (errno));
261 exit (1);
262 }
209 263
210 /* 264 /*
211 * prepare the command 265 * prepare the command
212 */ 266 */
213 _sntprintf (command, LINE_LEN, 267 snprintf (command, LINE_LEN,
214 _T ("netsh interface ipv4 add address \"%s\" %s %s"), 268 "netsh interface ipv4 add address \"%s\" %s %s",
215 device_visible_name, address, mask); 269 device_visible_name, address, mask);
216 /* 270 /*
217 * Set the address 271 * Set the address
@@ -221,8 +275,8 @@ set_address4 (const char *address, const char *mask)
221 /* Did it work?*/ 275 /* Did it work?*/
222 if (0 != ret) 276 if (0 != ret)
223 { 277 {
224 _ftprintf (stderr, _T ("Setting IPv4 address failed: %s\n"), strerror (ret)); 278 fprintf (stderr, "Setting IPv4 address failed: %s\n", strerror (ret));
225 exit (1); // FIXME: return error code, shut down interface / unload driver 279 exit (1); // FIXME: return error code, shut down interface / unload driver
226 } 280 }
227} 281}
228 282
@@ -240,8 +294,8 @@ setup_interface ()
240 * We do not directly input all the props here, because openvpn will update 294 * We do not directly input all the props here, because openvpn will update
241 * these details over time. 295 * these details over time.
242 */ 296 */
243 TCHAR inf_file_path[MAX_PATH]; 297 char inf_file_path[MAX_PATH];
244 TCHAR hwidlist[LINE_LEN + 4]; 298 char hwidlist[LINE_LEN + 4];
245 299
246 int str_lenth = 0; 300 int str_lenth = 0;
247 301
@@ -253,15 +307,15 @@ setup_interface ()
253 * TODO: Currently we just use TAP0901 as HWID, 307 * TODO: Currently we just use TAP0901 as HWID,
254 * but we might want to add additional information 308 * but we might want to add additional information
255 */ 309 */
256 _tcsncpy (hwidlist, HARDWARE_ID, LINE_LEN); 310 strncpy (hwidlist, HARDWARE_ID, LINE_LEN);
257 /** 311 /**
258 * this is kind of over-complicated, but allows keeps things independent of 312 * this is kind of over-complicated, but allows keeps things independent of
259 * how the openvpn-hwid is actually stored. 313 * how the openvpn-hwid is actually stored.
260 * 314 *
261 * A HWID list is double-\0 terminated and \0 separated 315 * A HWID list is double-\0 terminated and \0 separated
262 */ 316 */
263 str_lenth = _tcslen (hwidlist) + 1; 317 str_lenth = strlen (hwidlist) + 1;
264 _tcsncpy (&hwidlist[str_lenth], secondary_hwid, LINE_LEN - str_lenth); 318 strncpy (&hwidlist[str_lenth], secondary_hwid, LINE_LEN - str_lenth);
265 319
266 /** 320 /**
267 * Locate the inf-file, we need to store it somewhere where the system can 321 * Locate the inf-file, we need to store it somewhere where the system can
@@ -270,14 +324,14 @@ setup_interface ()
270 * TODO: How about win64 in the future? 324 * TODO: How about win64 in the future?
271 * We need to use a different driver for amd64/i386 ! 325 * We need to use a different driver for amd64/i386 !
272 */ 326 */
273 GetFullPathName (INF_FILE, MAX_PATH, inf_file_path, NULL); 327 GetFullPathNameA (INF_FILE, MAX_PATH, inf_file_path, NULL);
274 328
275 /** 329 /**
276 * Bootstrap our device info using the drivers inf-file 330 * Bootstrap our device info using the drivers inf-file
277 */ 331 */
278 if (!SetupDiGetINFClass (inf_file_path, 332 if (!SetupDiGetINFClassA (inf_file_path,
279 &guid, 333 &guid,
280 class, sizeof (class) / sizeof (TCHAR), 334 class, sizeof (class) / sizeof (char),
281 NULL)) 335 NULL))
282 return FALSE; 336 return FALSE;
283 337
@@ -290,7 +344,7 @@ setup_interface ()
290 return FALSE; 344 return FALSE;
291 345
292 DeviceNode.cbSize = sizeof (SP_DEVINFO_DATA); 346 DeviceNode.cbSize = sizeof (SP_DEVINFO_DATA);
293 if (!SetupDiCreateDeviceInfo (DeviceInfo, 347 if (!SetupDiCreateDeviceInfoA (DeviceInfo,
294 class, 348 class,
295 &guid, 349 &guid,
296 NULL, 350 NULL,
@@ -300,11 +354,11 @@ setup_interface ()
300 return FALSE; 354 return FALSE;
301 355
302 /* Deploy all the information collected into the registry */ 356 /* Deploy all the information collected into the registry */
303 if (!SetupDiSetDeviceRegistryProperty (DeviceInfo, 357 if (!SetupDiSetDeviceRegistryPropertyA (DeviceInfo,
304 &DeviceNode, 358 &DeviceNode,
305 SPDRP_HARDWAREID, 359 SPDRP_HARDWAREID,
306 (LPBYTE) hwidlist, 360 (LPBYTE) hwidlist,
307 (lstrlen (hwidlist) + 2) * sizeof (TCHAR))) 361 (strlen (hwidlist) + 2) * sizeof (char)))
308 return FALSE; 362 return FALSE;
309 363
310 /* Install our new class(=device) into the system */ 364 /* Install our new class(=device) into the system */
@@ -338,7 +392,7 @@ remove_interface ()
338 * 1. Prepare our existing device information set, and place the 392 * 1. Prepare our existing device information set, and place the
339 * uninstall related information into the structure 393 * uninstall related information into the structure
340 */ 394 */
341 if (!SetupDiSetClassInstallParams (DeviceInfo, 395 if (!SetupDiSetClassInstallParamsA (DeviceInfo,
342 (PSP_DEVINFO_DATA) & DeviceNode, 396 (PSP_DEVINFO_DATA) & DeviceNode,
343 &remove.ClassInstallHeader, 397 &remove.ClassInstallHeader,
344 sizeof (remove))) 398 sizeof (remove)))
@@ -367,25 +421,25 @@ resolve_interface_name ()
367{ 421{
368 422
369 SP_DEVINFO_LIST_DETAIL_DATA device_details; 423 SP_DEVINFO_LIST_DETAIL_DATA device_details;
370 TCHAR pnp_instance_id [MAX_DEVICE_ID_LEN]; 424 char pnp_instance_id [MAX_DEVICE_ID_LEN];
371 HKEY adapter_key_handle; 425 HKEY adapter_key_handle;
372 LONG status; 426 LONG status;
373 DWORD len; 427 DWORD len;
374 int i = 0; 428 int i = 0;
375 boolean retval = FALSE; 429 boolean retval = FALSE;
376 TCHAR adapter[] = _T (INTERFACE_REGISTRY_LOCATION); 430 char adapter[] = INTERFACE_REGISTRY_LOCATION;
377 431
378 /* We can obtain the PNP instance ID from our setupapi handle */ 432 /* We can obtain the PNP instance ID from our setupapi handle */
379 device_details.cbSize = sizeof (device_details); 433 device_details.cbSize = sizeof (device_details);
380 if (CR_SUCCESS != CM_Get_Device_ID_Ex (DeviceNode.DevInst, 434 if (CR_SUCCESS != CM_Get_Device_ID_ExA (DeviceNode.DevInst,
381 (PWSTR) pnp_instance_id, 435 (PCHAR) pnp_instance_id,
382 MAX_DEVICE_ID_LEN, 436 MAX_DEVICE_ID_LEN,
383 0, //must be 0 437 0, //must be 0
384 NULL)) //hMachine, we are local 438 NULL)) //hMachine, we are local
385 return FALSE; 439 return FALSE;
386 440
387 /* Now we can use this ID to locate the correct networks interface in registry */ 441 /* Now we can use this ID to locate the correct networks interface in registry */
388 if (ERROR_SUCCESS != RegOpenKeyEx ( 442 if (ERROR_SUCCESS != RegOpenKeyExA (
389 HKEY_LOCAL_MACHINE, 443 HKEY_LOCAL_MACHINE,
390 adapter, 444 adapter,
391 0, 445 0,
@@ -396,19 +450,19 @@ resolve_interface_name ()
396 /* Of course there is a multitude of entries here, with arbitrary names, 450 /* Of course there is a multitude of entries here, with arbitrary names,
397 * thus we need to iterate through there. 451 * thus we need to iterate through there.
398 */ 452 */
399 while (! retval) 453 while (!retval)
400 { 454 {
401 TCHAR instance_key[256]; 455 char instance_key[256];
402 TCHAR query_key [256]; 456 char query_key [256];
403 HKEY instance_key_handle; 457 HKEY instance_key_handle;
404 TCHAR pnpinstanceid_name[] = _T ("PnpInstanceID"); 458 char pnpinstanceid_name[] = "PnpInstanceID";
405 TCHAR pnpinstanceid_value[256]; 459 char pnpinstanceid_value[256];
406 TCHAR adaptername_name[] = _T ("Name"); 460 char adaptername_name[] = "Name";
407 DWORD data_type; 461 DWORD data_type;
408 462
409 len = sizeof (adapter_key_handle); 463 len = sizeof (adapter_key_handle);
410 /* optain a subkey of {4D36E972-E325-11CE-BFC1-08002BE10318} */ 464 /* optain a subkey of {4D36E972-E325-11CE-BFC1-08002BE10318} */
411 status = RegEnumKeyEx ( 465 status = RegEnumKeyExA (
412 adapter_key_handle, 466 adapter_key_handle,
413 i, 467 i,
414 instance_key, 468 instance_key,
@@ -426,13 +480,13 @@ resolve_interface_name ()
426 if (ERROR_SUCCESS != status) 480 if (ERROR_SUCCESS != status)
427 goto cleanup; 481 goto cleanup;
428 482
429 /* prepare our new querty string: */ 483 /* prepare our new query string: */
430 _sntprintf (query_key, 256, _T ("%s\\%s\\Connection"), 484 snprintf (query_key, 256, "%s\\%s\\Connection",
431 _T (INTERFACE_REGISTRY_LOCATION), 485 INTERFACE_REGISTRY_LOCATION,
432 instance_key); 486 instance_key);
433 487
434 /* look inside instance_key\\Connection */ 488 /* look inside instance_key\\Connection */
435 status = RegOpenKeyEx ( 489 status = RegOpenKeyExA (
436 HKEY_LOCAL_MACHINE, 490 HKEY_LOCAL_MACHINE,
437 query_key, 491 query_key,
438 0, 492 0,
@@ -444,7 +498,7 @@ resolve_interface_name ()
444 498
445 /* now, read our PnpInstanceID */ 499 /* now, read our PnpInstanceID */
446 len = sizeof (pnpinstanceid_value); 500 len = sizeof (pnpinstanceid_value);
447 status = RegQueryValueEx (instance_key_handle, 501 status = RegQueryValueExA (instance_key_handle,
448 pnpinstanceid_name, 502 pnpinstanceid_name,
449 NULL, //reserved, always NULL according to MSDN 503 NULL, //reserved, always NULL according to MSDN
450 &data_type, 504 &data_type,
@@ -455,12 +509,12 @@ resolve_interface_name ()
455 goto cleanup; 509 goto cleanup;
456 510
457 /* compare the value we got to our devices PNPInstanceID*/ 511 /* compare the value we got to our devices PNPInstanceID*/
458 if (0 != _tcsncmp (pnpinstanceid_value, pnp_instance_id, 512 if (0 != strncmp (pnpinstanceid_value, pnp_instance_id,
459 sizeof (pnpinstanceid_value) / sizeof (TCHAR))) 513 sizeof (pnpinstanceid_value) / sizeof (char)))
460 goto cleanup; 514 goto cleanup;
461 515
462 len = sizeof (device_visible_name); 516 len = sizeof (device_visible_name);
463 status = RegQueryValueEx ( 517 status = RegQueryValueExA (
464 instance_key_handle, 518 instance_key_handle,
465 adaptername_name, 519 adaptername_name,
466 NULL, //reserved, always NULL according to MSDN 520 NULL, //reserved, always NULL according to MSDN
@@ -491,7 +545,7 @@ cleanup:
491static int 545static int
492init_tun () 546init_tun ()
493{ 547{
494 int fd=-1; 548 int fd = -1;
495 549
496 if (!setup_interface ()) 550 if (!setup_interface ())
497 { 551 {
@@ -505,7 +559,13 @@ init_tun ()
505 return -1; 559 return -1;
506 } 560 }
507 561
508 562 //openvpn
563 /* get driver MTU */
564 // tun.c:2869
565
566 /* tun up: */
567 // tun.c: 3024
568
509 return fd; 569 return fd;
510} 570}
511 571
@@ -532,7 +592,19 @@ run (int fd_tun)
532 ssize_t bufin_rpos = 0; 592 ssize_t bufin_rpos = 0;
533 unsigned char *bufin_read = NULL; 593 unsigned char *bufin_read = NULL;
534 /* Hello, I am a stub function! I did my job, yay me! */ 594 /* Hello, I am a stub function! I did my job, yay me! */
595
596 //openvpn
597
598 // mainloop:
599 // tunnel_point_to_point
600 //openvpn.c:62
601
602 /* setup ansync IO */
603 //forward.c: 1515
535 604
605
606 //teardown:
607 //init.c:3472
536} 608}
537 609
538/** 610/**
@@ -549,8 +621,7 @@ run (int fd_tun)
549int 621int
550main (int argc, char **argv) 622main (int argc, char **argv)
551{ 623{
552 TCHAR hwid[LINE_LEN]; 624 char hwid[LINE_LEN];
553 TCHAR pid_as_string[LINE_LEN / 4];
554 int fd_tun; 625 int fd_tun;
555 int global_ret; 626 int global_ret;
556 627
@@ -561,16 +632,16 @@ main (int argc, char **argv)
561 } 632 }
562 633
563 strncpy (hwid, argv[1], LINE_LEN); 634 strncpy (hwid, argv[1], LINE_LEN);
564 hwid[LINE_LEN - 1] = _T ('\0'); 635 hwid[LINE_LEN - 1] = '\0';
565 636
566 /* 637 /*
567 * We use our PID for finding/resolving the control-panel name of our virtual 638 * We use our PID for finding/resolving the control-panel name of our virtual
568 * device. PIDs are (of course) unique at runtime, thus we can safely use it 639 * device. PIDs are (of course) unique at runtime, thus we can safely use it
569 * as additional hardware-id for our device. 640 * as additional hardware-id for our device.
570 */ 641 */
571 _itot (_getpid (), pid_as_string, 10); 642 snprintf (secondary_hwid, LINE_LEN / 2, "%s-%d",
572 strncpy (secondary_hwid, hwid, LINE_LEN); 643 hwid,
573 strncat (secondary_hwid, pid_as_string, LINE_LEN); // BUFFER OVERFLOW! 644 _getpid ());
574 645
575 if (-1 == (fd_tun = init_tun ())) 646 if (-1 == (fd_tun = init_tun ()))
576 { 647 {
@@ -605,26 +676,11 @@ main (int argc, char **argv)
605 676
606 set_address4 (address, mask); 677 set_address4 (address, mask);
607 } 678 }
608
609 /*TODO: attach network interface! (need to research how that works with ovpn )*/
610 679
611 /* 680 //eventuell:
612 uid_t uid = getuid (); 681 // tap_allow_nonadmin_access
613 if (0 != setresuid (uid, uid, uid)) 682 //tun.c:2023
614 {
615 fprintf (stderr, "Failed to setresuid: %s\n", strerror (errno));
616 global_ret = 2;
617 goto cleanup;
618 }
619 */
620 683
621 /*if (SIG_ERR == signal (SIGPIPE, SIG_IGN))
622 {
623 fprintf (stderr, "Failed to protect against SIGPIPE: %s\n",
624 strerror (errno));
625 // no exit, we might as well die with SIGPIPE should it ever happen
626 }
627 */
628 run (fd_tun); 684 run (fd_tun);
629 global_ret = 0; 685 global_ret = 0;
630cleanup: 686cleanup: