OpenVPN
Macros | Functions | Variables
openvpnmsica.c File Reference
#include <winsock2.h>
#include "openvpnmsica.h"
#include "msica_op.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 dependency graph for openvpnmsica.c:

Go to the source code of this file.

Macros

#define MSICA_INTERFACE_TICK_SIZE   (16*1024) /** Amount of tick space to reserve for one TAP/TUN interface creation/deletition. */
 Local constants. More...
 
#define openvpnmsica_debug_popup(f)
 

Functions

static DWORD openvpnmsica_setup_sequence_filename (_In_ MSIHANDLE hInstall, _In_z_ LPCTSTR szProperty, _Out_z_cap_(MAXPATH+1) LPTSTR szFilename)
 Creates a new sequence file in the current user's temporary folder and sets MSI property to its absolute path. More...
 
static UINT openvpnmsica_set_driver_certification (_In_ MSIHANDLE hInstall)
 Detects Windows version and sets DRIVERCERTIFICATION property to "", "whql", or "attsgn" accordingly. More...
 
static UINT openvpnmsica_set_openvpnserv_state (_In_ MSIHANDLE hInstall)
 Detects if the OpenVPNService service is in use (running or paused) and sets OPENVPNSERVICE to the service process PID, or its path if it is set to auto-start, but not running. More...
 
UINT __stdcall FindSystemInfo (_In_ MSIHANDLE hInstall)
 Determines Windows information: More...
 
UINT __stdcall FindTAPInterfaces (_In_ MSIHANDLE hInstall)
 Find existing TAP interfaces and set TAPINTERFACES property with semicolon delimited list of installed TAP interface GUIDs. 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...
 
UINT __stdcall EvaluateTAPInterfaces (_In_ MSIHANDLE hInstall)
 Evaluate the TAPInterface table of the MSI package database and prepare a list of TAP interfaces to install/remove. More...
 
UINT __stdcall ProcessDeferredAction (_In_ MSIHANDLE hInstall)
 Perform scheduled deferred action. More...
 

Variables

struct {
   LPCTSTR   szName
 
   TCHAR   szSuffix [3]
 Name of the cleanup action. More...
 
openvpnmsica_cleanup_action_seqs [MSICA_CLEANUP_ACTION_COUNT]
 Cleanup actions. More...
 

Macro Definition Documentation

◆ MSICA_INTERFACE_TICK_SIZE

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

Local constants.

Definition at line 60 of file openvpnmsica.c.

Referenced by EvaluateTAPInterfaces().

◆ openvpnmsica_debug_popup

#define openvpnmsica_debug_popup (   f)

Function Documentation

◆ 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 631 of file openvpnmsica.c.

References openvpnmsica_debug_popup.

◆ EvaluateTAPInterfaces()

UINT __stdcall EvaluateTAPInterfaces ( _In_ MSIHANDLE  hInstall)

Evaluate the TAPInterface table of the MSI package database and prepare a list of TAP interfaces 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 740 of file openvpnmsica.c.

References false, free, M_ERRNO, M_NONFATAL, msg, msi_format_field(), msi_get_record_string(), MSICA_INTERFACE_TICK_SIZE, msica_op_create_bool(), msica_op_create_string(), msica_op_rollback_enable, msica_op_seq_add_tail(), msica_op_seq_free(), msica_op_seq_init(), msica_op_seq_save(), msica_op_tap_interface_create, msica_op_tap_interface_delete_by_name, openvpnmsica_debug_popup, OPENVPNMSICA_SAVE_MSI_SESSION, openvpnmsica_setup_sequence_filename(), PRIsLPTSTR, and true.

◆ FindSystemInfo()

UINT __stdcall FindSystemInfo ( _In_ MSIHANDLE  hInstall)

Determines Windows information:

  • Sets DriverCertification MSI property to "", "attsgn" or "whql" according to the driver certification required by the running version of Windows.
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 442 of file openvpnmsica.c.

References openvpnmsica_debug_popup, OPENVPNMSICA_SAVE_MSI_SESSION, openvpnmsica_set_driver_certification(), and openvpnmsica_set_openvpnserv_state().

◆ FindTAPInterfaces()

UINT __stdcall FindTAPInterfaces ( _In_ MSIHANDLE  hInstall)

Find existing TAP interfaces and set TAPINTERFACES property with semicolon delimited list of installed TAP interface GUIDs.

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 466 of file openvpnmsica.c.

References free, tap_interface_node::guid, M_ERRNO, M_FATAL, M_NONFATAL, malloc, msg, openvpnmsica_debug_popup, OPENVPNMSICA_SAVE_MSI_SESSION, tap_interface_node::pNext, tap_free_interface_list(), and tap_list_interfaces().

◆ openvpnmsica_set_driver_certification()

static UINT openvpnmsica_set_driver_certification ( _In_ MSIHANDLE  hInstall)
static

Detects Windows version and sets DRIVERCERTIFICATION property to "", "whql", or "attsgn" accordingly.

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 216 of file openvpnmsica.c.

References free, M_ERRNO, M_NONFATAL, malloc, and msg.

Referenced by FindSystemInfo().

◆ openvpnmsica_set_openvpnserv_state()

static UINT openvpnmsica_set_openvpnserv_state ( _In_ MSIHANDLE  hInstall)
static

Detects if the OpenVPNService service is in use (running or paused) and sets OPENVPNSERVICE to the service process PID, or its path if it is set to auto-start, but not running.

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 339 of file openvpnmsica.c.

References M_ERRNO, M_NONFATAL, and msg.

Referenced by FindSystemInfo().

◆ openvpnmsica_setup_sequence_filename()

static DWORD openvpnmsica_setup_sequence_filename ( _In_ MSIHANDLE  hInstall,
_In_z_ LPCTSTR  szProperty,
_Out_z_cap_(MAXPATH+1) LPTSTR  szFilename 
)
static

Creates a new sequence file in the current user's temporary folder and sets MSI property to its absolute path.

Parameters
hInstallHandle to the installation provided to the DLL custom action
szPropertyMSI property name to set to the absolute path of the sequence file.
szFilenameString of minimum MAXPATH+1 characters where the zero-terminated file absolute path is stored.
Returns
ERROR_SUCCESS on success; An error code otherwise

Definition at line 90 of file openvpnmsica.c.

References _In_z_, free, M_ERRNO, M_FATAL, M_NONFATAL, malloc, msg, MSICA_CLEANUP_ACTION_COUNT, openvpnmsica_cleanup_action_seqs, PACKAGE_VERSION, PRIsLPTSTR, szName, and szSuffix.

Referenced by EvaluateTAPInterfaces().

◆ ProcessDeferredAction()

UINT __stdcall ProcessDeferredAction ( _In_ MSIHANDLE  hInstall)

◆ 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 654 of file openvpnmsica.c.

References free, M_ERRNO, M_FATAL, M_NONFATAL, malloc, msg, openvpnmsica_debug_popup, and OPENVPNMSICA_SAVE_MSI_SESSION.

Variable Documentation

◆ openvpnmsica_cleanup_action_seqs

const { ... } openvpnmsica_cleanup_action_seqs[MSICA_CLEANUP_ACTION_COUNT]
Initial value:
=
{
{ TEXT("Commit" ), TEXT("cm") },
{ TEXT("Rollback"), TEXT("rb") },
}

Cleanup actions.

Referenced by openvpnmsica_setup_sequence_filename(), and ProcessDeferredAction().

◆ szName

LPCTSTR szName

◆ szSuffix

TCHAR szSuffix[3]

Name of the cleanup action.

This name is appended to the deferred custom action name (e.g. "InstallTAPInterfaces" >> "InstallTAPInterfacesCommit").

Definition at line 68 of file openvpnmsica.c.

Referenced by openvpnmsica_setup_sequence_filename(), and ProcessDeferredAction().