|
OpenVPN
|
#include <winsock2.h>#include "openvpnmsica.h"#include "msica_arg.h"#include "msiex.h"#include "../tapctl/basic.h"#include "../tapctl/error.h"#include "../tapctl/tap.h"#include <windows.h>#include <iphlpapi.h>#include <malloc.h>#include <memory.h>#include <msiquery.h>#include <shellapi.h>#include <shlwapi.h>#include <stdbool.h>#include <stdlib.h>#include <wchar.h>#include <setupapi.h>#include <newdev.h>#include <initguid.h>#include <devguid.h>
Go to the source code of this file.
Macros | |
| #define | MSICA_ADAPTER_TICK_SIZE (16 * 1024) |
| Local constants. | |
| #define | FILE_NEED_REBOOT L".ovpn_need_reboot" |
| #define | OPENVPN_CONNECT_ADAPTER_SUBSTR L"OpenVPN Connect" |
| #define | debug_popup(f) |
Functions | |
| static UINT | setup_sequence (_In_ MSIHANDLE hInstall, _In_z_ LPCWSTR szProperty, _In_ struct msica_arg_seq *seq) |
| Joins an argument sequence and sets it to the MSI property. | |
| static void | find_adapters (_In_ MSIHANDLE hInstall, _In_z_ LPCWSTR szzHardwareIDs, _In_z_ LPCWSTR szAdaptersPropertyName, _In_z_ LPCWSTR szActiveAdaptersPropertyName) |
| UINT __stdcall | FindSystemInfo (_In_ MSIHANDLE hInstall) |
| Determines Windows information: | |
| UINT __stdcall | CloseOpenVPNGUI (_In_ MSIHANDLE hInstall) |
| Find OpenVPN GUI window and send it a WM_CLOSE message. | |
| UINT __stdcall | StartOpenVPNGUI (_In_ MSIHANDLE hInstall) |
| Launches OpenVPN GUI. | |
| static DWORD | schedule_adapter_create (_Inout_ struct msica_arg_seq *seq, _Inout_opt_ struct msica_arg_seq *seqRollback, _In_z_ LPCWSTR szDisplayName, _In_z_ LPCWSTR szHardwareId, _Inout_ int *iTicks) |
| Schedules adapter creation. | |
| static DWORD | schedule_adapter_delete (_Inout_ struct msica_arg_seq *seq, _Inout_opt_ struct msica_arg_seq *seqCommit, _Inout_opt_ struct msica_arg_seq *seqRollback, _In_z_ LPCWSTR szDisplayName, _In_z_ LPCWSTR szzHardwareIDs, _Inout_ int *iTicks) |
| Schedules adapter deletion. | |
| UINT __stdcall | EvaluateTUNTAPAdapters (_In_ MSIHANDLE hInstall) |
| Evaluate the TUNTAPAdapter table of the MSI package database and prepare a list of TAP adapters to install/remove. | |
| static BOOL | parse_guid (_In_z_ LPCWSTR szArg, _Out_ GUID *guid) |
| Parses string encoded GUID. | |
| static void | CreateRebootFile (_In_z_ LPCWSTR szTmpDir) |
| Create empty file in user's temp directory. | |
| UINT __stdcall | ProcessDeferredAction (_In_ MSIHANDLE hInstall) |
| Perform scheduled deferred action. | |
| UINT __stdcall | CheckAndScheduleReboot (_In_ MSIHANDLE hInstall) |
| Schedule reboot after installation if reboot indication file is found in user's temp directory. | |
| #define debug_popup | ( | f | ) |
Definition at line 137 of file openvpnmsica.c.
| #define FILE_NEED_REBOOT L".ovpn_need_reboot" |
Definition at line 64 of file openvpnmsica.c.
| #define MSICA_ADAPTER_TICK_SIZE (16 * 1024) |
Local constants.
Amount of tick space to reserve for one TAP/TUN adapter creation/deletition.
Definition at line 62 of file openvpnmsica.c.
| #define OPENVPN_CONNECT_ADAPTER_SUBSTR L"OpenVPN Connect" |
Definition at line 66 of file openvpnmsica.c.
| UINT __stdcall CheckAndScheduleReboot | ( | _In_ MSIHANDLE | hInstall | ) |
Schedule reboot after installation if reboot indication file is found in user's temp directory.
| hInstall | Handle to the installation provided to the DLL custom action |
Definition at line 1169 of file openvpnmsica.c.
References debug_popup, FILE_NEED_REBOOT, M_WARN, msg, and OPENVPNMSICA_SAVE_MSI_SESSION.
| UINT __stdcall CloseOpenVPNGUI | ( | _In_ MSIHANDLE | hInstall | ) |
Find OpenVPN GUI window and send it a WM_CLOSE message.
| hInstall | Handle to the installation provided to the DLL custom action |
Definition at line 338 of file openvpnmsica.c.
References debug_popup.
|
static |
Create empty file in user's temp directory.
The existence of this file is checked in the end of installation by ScheduleReboot immediate custom action which schedules reboot.
| szTmpDir | path to user's temp dirctory |
Definition at line 947 of file openvpnmsica.c.
References FILE_NEED_REBOOT, M_ERRNO, M_NONFATAL, M_WARN, and msg.
Referenced by ProcessDeferredAction().
| UINT __stdcall EvaluateTUNTAPAdapters | ( | _In_ MSIHANDLE | hInstall | ) |
Evaluate the TUNTAPAdapter table of the MSI package database and prepare a list of TAP adapters to install/remove.
| hInstall | Handle to the installation provided to the DLL custom action |
Definition at line 623 of file openvpnmsica.c.
References debug_popup, M_ERRNO, M_NONFATAL, msg, msi_format_field(), msi_get_record_string(), msica_arg_seq_add_tail(), msica_arg_seq_free(), msica_arg_seq_init(), OPENVPNMSICA_SAVE_MSI_SESSION, schedule_adapter_create(), schedule_adapter_delete(), and setup_sequence().
|
static |
Definition at line 141 of file openvpnmsica.c.
References tap_adapter_node::guid, M_ERRNO, M_FATAL, M_NONFATAL, M_WARN, msg, OPENVPN_CONNECT_ADAPTER_SUBSTR, tap_adapter_node::pNext, tap_adapter_node::szzHardwareIDs, tap_free_adapter_list(), and tap_list_adapters().
Referenced by FindSystemInfo().
| UINT __stdcall FindSystemInfo | ( | _In_ MSIHANDLE | hInstall | ) |
Determines Windows information:
OPENVPNSERVICE MSI property to PID of OpenVPN Service if running, or its EXE path if configured for auto-start.| hInstall | Handle to the installation provided to the DLL custom action |
Definition at line 311 of file openvpnmsica.c.
References _L, debug_popup, find_adapters(), and OPENVPNMSICA_SAVE_MSI_SESSION.
Parses string encoded GUID.
| szArg | Zero terminated string where the GUID string starts |
| guid | Pointer to GUID that receives parsed value |
Definition at line 927 of file openvpnmsica.c.
References _L, M_ERRNO, M_NONFATAL, msg, PRIGUID_PARAM_REF, and PRIXGUID.
Referenced by ProcessDeferredAction().
| UINT __stdcall ProcessDeferredAction | ( | _In_ MSIHANDLE | hInstall | ) |
Perform scheduled deferred action.
| hInstall | Handle to the installation provided to the DLL custom action |
Definition at line 966 of file openvpnmsica.c.
References cleanup(), CreateRebootFile(), debug_popup, tap_adapter_node::guid, i, M_ERRNO, M_NONFATAL, msg, msi_get_string(), MSICA_ADAPTER_TICK_SIZE, OPENVPNMSICA_SAVE_MSI_SESSION, parse_guid(), tap_adapter_node::pNext, tap_adapter_node::szName, tap_create_adapter(), tap_delete_adapter(), tap_enable_adapter(), tap_free_adapter_list(), tap_list_adapters(), and tap_set_adapter_name().
|
static |
Schedules adapter creation.
When the rollback is enabled, the adapter deletition is scheduled on rollback.
| seq | The argument sequence to pass to InstallTUNTAPAdapters custom action |
| seqRollback | The argument sequence to pass to InstallTUNTAPAdaptersRollback custom action. NULL when rollback is disabled. |
| szDisplayName | Adapter display name |
| szHardwareId | Adapter hardware ID |
| iTicks | Pointer to an integer that represents amount of work (on progress indicator) the InstallTUNTAPAdapters will take. This function increments it by MSICA_ADAPTER_TICK_SIZE for each adapter to create. |
Definition at line 470 of file openvpnmsica.c.
References M_NONFATAL, msg, MSICA_ADAPTER_TICK_SIZE, msica_arg_seq_add_head(), msica_arg_seq_add_tail(), tap_adapter_node::pNext, tap_free_adapter_list(), and tap_list_adapters().
Referenced by EvaluateTUNTAPAdapters().
|
static |
Schedules adapter deletion.
When the rollback is enabled, the adapter deletition is scheduled as: disable in UninstallTUNTAPAdapters, enable on rollback, delete on commit.
When rollback is disabled, the adapter deletition is scheduled as delete in UninstallTUNTAPAdapters.
| seq | The argument sequence to pass to UninstallTUNTAPAdapters custom action |
| seqCommit | The argument sequence to pass to UninstallTUNTAPAdaptersCommit custom action. NULL when rollback is disabled. |
| seqRollback | The argument sequence to pass to UninstallTUNTAPAdaptersRollback custom action. NULL when rollback is disabled. |
| szDisplayName | Adapter display name |
| szzHardwareIDs | String of strings with acceptable adapter hardware IDs |
| iTicks | Pointer to an integer that represents amount of work (on progress indicator) the UninstallTUNTAPAdapters will take. This function increments it by MSICA_ADAPTER_TICK_SIZE for each adapter to delete. |
Definition at line 566 of file openvpnmsica.c.
References _L, MSICA_ADAPTER_TICK_SIZE, msica_arg_seq_add_head(), msica_arg_seq_add_tail(), tap_adapter_node::pNext, PRIGUID_PARAM, PRIXGUID, tap_adapter_node::szzHardwareIDs, tap_free_adapter_list(), and tap_list_adapters().
Referenced by EvaluateTUNTAPAdapters().
|
static |
Joins an argument sequence and sets it to the MSI property.
| hInstall | Handle to the installation provided to the DLL custom action |
| szProperty | MSI property name to set to the joined argument sequence. |
| seq | The argument sequence. |
Definition at line 80 of file openvpnmsica.c.
References M_ERRNO, M_NONFATAL, msg, and msica_arg_seq_join().
Referenced by EvaluateTUNTAPAdapters().
| UINT __stdcall StartOpenVPNGUI | ( | _In_ MSIHANDLE | hInstall | ) |
Launches OpenVPN GUI.
It's path is obtained by expanding the [#bin.openvpn_gui.exe] therefore, its Id field in File table must be "bin.openvpn_gui.exe".
| hInstall | Handle to the installation provided to the DLL custom action |
Definition at line 362 of file openvpnmsica.c.
References debug_popup, M_ERRNO, M_FATAL, M_NONFATAL, msg, and OPENVPNMSICA_SAVE_MSI_SESSION.