OpenVPN
Macros | Functions
openvpnmsica.c File Reference
#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 <tchar.h>
#include <setupapi.h>
#include <newdev.h>
#include <initguid.h>
#include <devguid.h>
Include dependency graph for openvpnmsica.c:

Go to the source code of this file.

Macros

#define MSICA_ADAPTER_TICK_SIZE   (16*1024) /** Amount of tick space to reserve for one TAP/TUN adapter creation/deletition. */
 Local constants. More...
 
#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_ LPCTSTR szProperty, _In_ struct msica_arg_seq *seq)
 Joins an argument sequence and sets it to the MSI property. More...
 
static void find_adapters (_In_ MSIHANDLE hInstall, _In_z_ LPCTSTR szzHardwareIDs, _In_z_ LPCTSTR szAdaptersPropertyName, _In_z_ LPCTSTR szActiveAdaptersPropertyName)
 
UINT __stdcall FindSystemInfo (_In_ MSIHANDLE hInstall)
 Determines Windows information: More...
 
UINT __stdcall CloseOpenVPNGUI (_In_ MSIHANDLE hInstall)
 Find OpenVPN GUI window and send it a WM_CLOSE message. More...
 
UINT __stdcall StartOpenVPNGUI (_In_ MSIHANDLE hInstall)
 Launches OpenVPN GUI. More...
 
static DWORD schedule_adapter_create (_Inout_ struct msica_arg_seq *seq, _Inout_opt_ struct msica_arg_seq *seqRollback, _In_z_ LPCTSTR szDisplayName, _In_z_ LPCTSTR szHardwareId, _Inout_ int *iTicks)
 Schedules adapter creation. More...
 
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_ LPCTSTR szDisplayName, _In_z_ LPCTSTR szzHardwareIDs, _Inout_ int *iTicks)
 Schedules adapter deletion. More...
 
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. More...
 
static BOOL parse_guid (_In_z_ LPCWSTR szArg, _Out_ GUID *guid)
 Parses string encoded GUID. More...
 
static void CreateRebootFile (_In_z_ LPCWSTR szTmpDir)
 Create empty file in user's temp directory. More...
 
UINT __stdcall ProcessDeferredAction (_In_ MSIHANDLE hInstall)
 Perform scheduled deferred action. More...
 
UINT __stdcall CheckAndScheduleReboot (_In_ MSIHANDLE hInstall)
 Schedule reboot after installation if reboot indication file is found in user's temp directory. More...
 

Macro Definition Documentation

◆ debug_popup

#define debug_popup (   f)

Definition at line 141 of file openvpnmsica.c.

◆ FILE_NEED_REBOOT

#define FILE_NEED_REBOOT   L".ovpn_need_reboot"

Definition at line 64 of file openvpnmsica.c.

◆ MSICA_ADAPTER_TICK_SIZE

#define MSICA_ADAPTER_TICK_SIZE   (16*1024) /** Amount of tick space to reserve for one TAP/TUN adapter creation/deletition. */

Local constants.

Definition at line 62 of file openvpnmsica.c.

◆ OPENVPN_CONNECT_ADAPTER_SUBSTR

#define OPENVPN_CONNECT_ADAPTER_SUBSTR   L"OpenVPN Connect"

Definition at line 66 of file openvpnmsica.c.

Function Documentation

◆ CheckAndScheduleReboot()

UINT __stdcall CheckAndScheduleReboot ( _In_ MSIHANDLE  hInstall)

Schedule reboot after installation if reboot indication file is found in user's temp directory.

Parameters
hInstallHandle to the installation provided to the DLL custom action
Returns
ERROR_SUCCESS on success; An error code otherwise See: https://msdn.microsoft.com/en-us/library/windows/desktop/aa368072.aspx

Definition at line 1163 of file openvpnmsica.c.

References debug_popup, FILE_NEED_REBOOT, M_WARN, msg, and OPENVPNMSICA_SAVE_MSI_SESSION.

◆ CloseOpenVPNGUI()

UINT __stdcall CloseOpenVPNGUI ( _In_ MSIHANDLE  hInstall)

Find OpenVPN GUI window and send it a WM_CLOSE message.

Parameters
hInstallHandle to the installation provided to the DLL custom action
Returns
ERROR_SUCCESS on success; An error code otherwise See: https://msdn.microsoft.com/en-us/library/windows/desktop/aa368072.aspx

Definition at line 338 of file openvpnmsica.c.

References debug_popup.

◆ CreateRebootFile()

static void CreateRebootFile ( _In_z_ LPCWSTR  szTmpDir)
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.

Parameters
szTmpDirpath to user's temp dirctory

Definition at line 944 of file openvpnmsica.c.

References FILE_NEED_REBOOT, M_ERRNO, M_NONFATAL, M_WARN, and msg.

Referenced by ProcessDeferredAction().

◆ EvaluateTUNTAPAdapters()

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.

Parameters
hInstallHandle to the installation provided to the DLL custom action
Returns
ERROR_SUCCESS on success; An error code otherwise See: https://msdn.microsoft.com/en-us/library/windows/desktop/aa368072.aspx

Definition at line 634 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, PRIsLPTSTR, schedule_adapter_create(), schedule_adapter_delete(), and setup_sequence().

◆ find_adapters()

static void find_adapters ( _In_ MSIHANDLE  hInstall,
_In_z_ LPCTSTR  szzHardwareIDs,
_In_z_ LPCTSTR  szAdaptersPropertyName,
_In_z_ LPCTSTR  szActiveAdaptersPropertyName 
)
static

◆ FindSystemInfo()

UINT __stdcall FindSystemInfo ( _In_ MSIHANDLE  hInstall)

Determines Windows information:

  • Sets OPENVPNSERVICE MSI property to PID of OpenVPN Service if running, or its EXE path if configured for auto-start.
  • Finds existing TAP-Windows6 adapters and set TAPWINDOWS6ADAPTERS and ACTIVETAPWINDOWS6ADAPTERS properties with semicolon delimited list of all installed adapter GUIDs and active adapter GUIDs respectively.
  • Finds existing Wintun adapters and set WINTUNADAPTERS and ACTIVEWINTUNADAPTERS properties with semicolon delimited list of all installed adapter GUIDs and active adapter GUIDs respectively.
  • Finds existing ovpn-dco adapters and set OVPNDCOADAPTERS and ACTIVEOVPNDCOADAPTERS properties with semicolon delimited list of all installed adapter GUIDs and active adapter GUIDs respectively.
Parameters
hInstallHandle to the installation provided to the DLL custom action
Returns
ERROR_SUCCESS on success; An error code otherwise See: https://msdn.microsoft.com/en-us/library/windows/desktop/aa368072.aspx

Definition at line 301 of file openvpnmsica.c.

References debug_popup, find_adapters(), OPENVPNMSICA_SAVE_MSI_SESSION, and TAP_WIN_COMPONENT_ID.

◆ parse_guid()

static BOOL parse_guid ( _In_z_ LPCWSTR  szArg,
_Out_ GUID *  guid 
)
static

Parses string encoded GUID.

Parameters
szArgZero terminated string where the GUID string starts
guidPointer to GUID that receives parsed value
Returns
TRUE on success; FALSE otherwise

Definition at line 922 of file openvpnmsica.c.

References _L, M_ERRNO, M_NONFATAL, msg, PRIGUID_PARAM_REF, and PRIXGUID.

Referenced by ProcessDeferredAction().

◆ ProcessDeferredAction()

UINT __stdcall ProcessDeferredAction ( _In_ MSIHANDLE  hInstall)

◆ schedule_adapter_create()

static DWORD schedule_adapter_create ( _Inout_ struct msica_arg_seq seq,
_Inout_opt_ struct msica_arg_seq seqRollback,
_In_z_ LPCTSTR  szDisplayName,
_In_z_ LPCTSTR  szHardwareId,
_Inout_ int *  iTicks 
)
static

Schedules adapter creation.

When the rollback is enabled, the adapter deletition is scheduled on rollback.

Parameters
seqThe argument sequence to pass to InstallTUNTAPAdapters custom action
seqRollbackThe argument sequence to pass to InstallTUNTAPAdaptersRollback custom action. NULL when rollback is disabled.
szDisplayNameAdapter display name
szHardwareIdAdapter hardware ID
iTicksPointer 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.
Returns
ERROR_SUCCESS on success; An error code otherwise

Definition at line 467 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, PRIsLPTSTR, tap_free_adapter_list(), and tap_list_adapters().

Referenced by EvaluateTUNTAPAdapters().

◆ schedule_adapter_delete()

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_ LPCTSTR  szDisplayName,
_In_z_ LPCTSTR  szzHardwareIDs,
_Inout_ int *  iTicks 
)
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.

Parameters
seqThe argument sequence to pass to UninstallTUNTAPAdapters custom action
seqCommitThe argument sequence to pass to UninstallTUNTAPAdaptersCommit custom action. NULL when rollback is disabled.
seqRollbackThe argument sequence to pass to UninstallTUNTAPAdaptersRollback custom action. NULL when rollback is disabled.
szDisplayNameAdapter display name
szzHardwareIDsString of strings with acceptable adapter hardware IDs
iTicksPointer 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.
Returns
ERROR_SUCCESS on success; An error code otherwise

Definition at line 567 of file openvpnmsica.c.

References 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().

◆ setup_sequence()

static UINT setup_sequence ( _In_ MSIHANDLE  hInstall,
_In_z_ LPCTSTR  szProperty,
_In_ struct msica_arg_seq seq 
)
static

Joins an argument sequence and sets it to the MSI property.

Parameters
hInstallHandle to the installation provided to the DLL custom action
szPropertyMSI property name to set to the joined argument sequence.
seqThe argument sequence.
Returns
ERROR_SUCCESS on success; An error code otherwise

Definition at line 80 of file openvpnmsica.c.

References M_ERRNO, M_NONFATAL, msg, msica_arg_seq_join(), and PRIsLPTSTR.

Referenced by EvaluateTUNTAPAdapters().

◆ StartOpenVPNGUI()

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".

Parameters
hInstallHandle to the installation provided to the DLL custom action
Returns
ERROR_SUCCESS on success; An error code otherwise See: https://msdn.microsoft.com/en-us/library/windows/desktop/aa368072.aspx

Definition at line 361 of file openvpnmsica.c.

References debug_popup, M_ERRNO, M_FATAL, M_NONFATAL, msg, and OPENVPNMSICA_SAVE_MSI_SESSION.