aboutsummaryrefslogtreecommitdiffstats
path: root/api/adapter.c (follow)
Commit message (Collapse)AuthorAgeFilesLines
* api: selectively use temporary variable to prepare outputSimon Rozman2020-10-311-25/+33
| | | | | Suggested-by: Jason A. Donenfeld <Jason@zx2c4.com> Signed-off-by: Simon Rozman <simon@rozman.si>
* api: remove security attributes debug trap doorJason A. Donenfeld2020-10-311-5/+5
| | | | Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
* api: elevate only when needed for system operationsJason A. Donenfeld2020-10-311-9/+42
| | | | Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
* api: simplify driver selection by always including EV driverSimon Rozman2020-10-311-3/+1
| | | | | | | | When Windows 7-8.1 support is sunset, there will be no more EV driver deployment at all. Suggested-by: Jason A. Donenfeld <Jason@zx2c4.com> Signed-off-by: Simon Rozman <simon@rozman.si>
* api: simplify driver removalSimon Rozman2020-10-311-4/+30
| | | | | | | | | | | | | | | | | When we install the Wintun driver to the store, we get exact oem<nn>.inf filename of the driver in the store we just installed. Since the installation should be only temporarily, we should uninstall only the driver we installed. This also eliminates the need for iterating driver store speeding up things. The code we removed was inherited from the installer.dll, where it made perfect sense to remove all installed Wintun drivers in the update process. Suggested-by: Jason A. Donenfeld <Jason@zx2c4.com> Signed-off-by: Simon Rozman <simon@rozman.si>
* api: make #ifdef-s more descriptiveSimon Rozman2020-10-311-5/+5
| | | | | Suggested-by: Jason A. Donenfeld <Jason@zx2c4.com> Signed-off-by: Simon Rozman <simon@rozman.si>
* api: cleanup driver selection logicSimon Rozman2020-10-311-17/+5
| | | | | | | | With all the platforms (including ARM) having at least one driver now, the dead-code removal #ifdef-s are no longer required. Suggested-by: Jason A. Donenfeld <Jason@zx2c4.com> Signed-off-by: Simon Rozman <simon@rozman.si>
* api: split adapter creation/deletion to delegator and worker functionsSimon Rozman2020-10-311-75/+92
| | | | | Suggested-by: Jason A. Donenfeld <Jason@zx2c4.com> Signed-off-by: Simon Rozman <simon@rozman.si>
* api: make pipe handles non-inheritable by defaultSimon Rozman2020-10-311-7/+4
| | | | | | | | | ...and change to inheritable only the ones really needed, eliminating a window where we'd have inheritable handles that are not supposed to be inheritable. Suggested-by: Jason A. Donenfeld <Jason@zx2c4.com> Signed-off-by: Simon Rozman <simon@rozman.si>
* api: check the stdout reader thread exit status for failuresSimon Rozman2020-10-311-34/+38
| | | | | | | ...and refactor the ExecuteRunDll32(). Reported-by: Jason A. Donenfeld <Jason@zx2c4.com> Signed-off-by: Simon Rozman <simon@rozman.si>
* api: make architecture-dependent wintun.dll selection an explicit selectSimon Rozman2020-10-311-3/+15
| | | | | Suggested-by: Jason A. Donenfeld <Jason@zx2c4.com> Signed-off-by: Simon Rozman <simon@rozman.si>
* api: fix adapter name numbering terminationSimon Rozman2020-10-311-1/+1
| | | | | Reported-by: Jason A. Donenfeld <Jason@zx2c4.com> Signed-off-by: Simon Rozman <simon@rozman.si>
* api: bail out on _TRUNCATE truncationSimon Rozman2020-10-311-48/+91
| | | | | | | | | | Silently ignoring truncation of the strings(like adapter and pool names, registry paths etc.) leads to strange failures later down the road (like registry key not found) masking the true reason of the failure. This makes troubleshooting difficult. Reported-by: Jason A. Donenfeld <Jason@zx2c4.com> Signed-off-by: Simon Rozman <simon@rozman.si>
* api: simplify RemoveNumberedSuffix()Simon Rozman2020-10-311-20/+7
| | | | | Reported-by: Jason A. Donenfeld <Jason@zx2c4.com> Signed-off-by: Simon Rozman <simon@rozman.si>
* api: use C locale for adapter and pool name case-insensitive comparingSimon Rozman2020-10-311-13/+4
| | | | | Reported-by: Jason A. Donenfeld <Jason@zx2c4.com> Signed-off-by: Simon Rozman <simon@rozman.si>
* api: fix zero-parameter C function prototypesSimon Rozman2020-10-311-4/+4
| | | | | Reported-by: Jason A. Donenfeld <Jason@zx2c4.com> Signed-off-by: Simon Rozman <simon@rozman.si>
* api: fallback to hard-coded versionSimon Rozman2020-10-311-2/+2
| | | | | | | Windows 7 doesn't have DriverMajorVersion and DriverMinorVersion registry values yet. Signed-off-by: Simon Rozman <simon@rozman.si>
* api: use catalog file for signing certificate extractionSimon Rozman2020-10-311-1/+1
| | | | | | | | The .sys file of the driver does not need to be digitally signed. It is the .cat file that Windows is checking for complete driver .inf+.sys+ .cat bundle. Signed-off-by: Simon Rozman <simon@rozman.si>
* api: switch to private heapSimon Rozman2020-10-301-42/+32
| | | | | | | We must not use the process heap, as it is changeable. Client may change it causing our HeapFree() to use wrong heap. Signed-off-by: Simon Rozman <simon@rozman.si>
* api: revise loggingSimon Rozman2020-10-301-6/+6
| | | | | | | | | | | | RegistryQueryString() may produce one or more "File not found" errors when called from RegistryQueryStringWait() - which is expected while waiting. Those errors were annoying and awkward to read in the log. Furthermore, should RegistryQueryString() fail, it already displays detailed Windows error message and the parent's logging was simplified to prevent repetitions in the log. Signed-off-by: Simon Rozman <simon@rozman.si>
* api: connect rundll32 child with parent using stdout and stderrSimon Rozman2020-10-301-10/+195
| | | | | | | | | | | | | | | | | The WintunCreateAdapter()+CreateAdapter() and WintunDeleteAdapter()+ DeleteAdapter() communicate using Unicode anonymous pipes now. This allows the WintunCreateAdapter() to exactly determine the adapter CreateAdapter() just created by its GUID rather than its name - avoiding the possible ambiguity caused by same-adapter-name ordinal suffixes. This also allows exact retrieval of the result code and pending reboot flag from the rundll32 child process. Furthermore, CreateAdapter() and DeleteAdapter() are now available in _DEBUG for all platforms to allow testing. It took a #pragma comment( linker, "/EXPORT") trick to stop compiler from decorating function names and exporting as _CreateAdapter@16() and _DeleteAdapter@16() in x86. Signed-off-by: Simon Rozman <simon@rozman.si>
* api: use standard C voidSimon Rozman2020-10-301-1/+1
| | | | Signed-off-by: Simon Rozman <simon@rozman.si>
* api: fix grammarSimon Rozman2020-10-301-11/+11
| | | | | Reported-by: Jason A. Donenfeld <Jason@zx2c4.com> Signed-off-by: Simon Rozman <simon@rozman.si>
* api: fix dead code warning for arm platformSimon Rozman2020-10-301-65/+72
| | | | | | arm platform has no driver leading to a lot of dead code. Signed-off-by: Simon Rozman <simon@rozman.si>
* api: build the bridge from WoW64 to native inSimon Rozman2020-10-301-10/+154
| | | | | | | | SetupAPI fails to create a device in WoW64 processes. x86 (and arm) wintun.dll pack the amd64 and arm64 wintun.dll now, and use rundll32 to create a native process to do the job where required. Signed-off-by: Simon Rozman <simon@rozman.si>
* api: test the temporary driver ideaSimon Rozman2020-10-301-3/+187
| | | | | | | | | | | | | | | | | | | | | | 1. Add driver to the store: SetupCopyOEMInfW() 2. Create the adapter using explicit path to .inf file: DI_ENUMSINGLEINF 3. Delete all Wintun drivers from the store. This is a subject of further research: - It appears those adapters survive a reboot. So, Windows must store the driver somewhere on the disk and the driver removal is not completed. If the driver removal is not completed until there are existing adapters, this is excellent, as it will provide a self-cleanup. - Test multiple adapters with different driver versions. Which driver wins? - Are other Wintun adapters interrupted when adding a new one? - Test Windows 7 behaviour. Signed-off-by: Simon Rozman <simon@rozman.si>
* api: move documentation to .h and discontinue on static functionsSimon Rozman2020-10-301-278/+0
| | | | | | | | | While Doxygen correctly locates the function documentation when it is written directly preceding the function body, Microsoft Visual Studio IDE does not. The former requires the documentation to precede the function declaration. Signed-off-by: Simon Rozman <simon@rozman.si>
* api: log out-of-memory errors tooSimon Rozman2020-10-301-16/+8
| | | | | | | It's not likely the write to log will succeed in low memory condition thou. Signed-off-by: Simon Rozman <simon@rozman.si>
* api: stop double error status reportingSimon Rozman2020-10-301-29/+26
| | | | | | | When an internal function logs an error and its cause, it bloats the log when the caller logs the cause again. Signed-off-by: Simon Rozman <simon@rozman.si>
* api: internal reorganizationSimon Rozman2020-10-301-0/+1463
Gather adapter management in adapter.h/.c (formerly devmgmt.h/.c) and unify HwID tests. Use "Namespace" namespace in all functions from namespace.h/.c. Fix char strings in LOG_... Signed-off-by: Simon Rozman <simon@rozman.si>