OpenVPN
Enumerations | Functions | Variables
win32.c File Reference
#include "syshead.h"
#include "buffer.h"
#include "error.h"
#include "mtu.h"
#include "run_command.h"
#include "sig.h"
#include "win32-util.h"
#include "win32.h"
#include "openvpn-msg.h"
#include "memdbg.h"
#include <versionhelpers.h>
#include "block_dns.h"
Include dependency graph for win32.c:

Go to the source code of this file.

Enumerations

enum  arch_t {
  ARCH_X86, ARCH_AMD64, ARCH_ARM64, ARCH_NATIVE,
  ARCH_UNKNOWN
}
 

Functions

static void set_openssl_env_vars ()
 Set OpenSSL environment variables to a safe directory. More...
 
void init_win32 (void)
 
void uninit_win32 (void)
 
void set_pause_exit_win32 (void)
 
bool init_security_attributes_allow_all (struct security_attributes *obj)
 
void overlapped_io_init (struct overlapped_io *o, const struct frame *frame, BOOL event_state)
 
void overlapped_io_close (struct overlapped_io *o)
 
char * overlapped_io_state_ascii (const struct overlapped_io *o)
 
void init_net_event_win32 (struct rw_handle *event, long network_events, socket_descriptor_t sd, unsigned int flags)
 
long reset_net_event_win32 (struct rw_handle *event, socket_descriptor_t sd)
 
void close_net_event_win32 (struct rw_handle *event, socket_descriptor_t sd, unsigned int flags)
 
void net_event_win32_init (struct net_event_win32 *ne)
 
void net_event_win32_start (struct net_event_win32 *ne, long network_events, socket_descriptor_t sd)
 
void net_event_win32_reset_write (struct net_event_win32 *ne)
 
void net_event_win32_reset (struct net_event_win32 *ne)
 
void net_event_win32_stop (struct net_event_win32 *ne)
 
void net_event_win32_close (struct net_event_win32 *ne)
 
static void win_trigger_event (struct win32_signal *ws)
 
static bool WINAPI win_ctrl_handler (DWORD signum)
 
void win32_signal_clear (struct win32_signal *ws)
 
void win32_signal_open (struct win32_signal *ws, int force, const char *exit_event_name, bool exit_event_initial_state)
 
static bool keyboard_input_available (struct win32_signal *ws)
 
static unsigned int keyboard_ir_to_key (INPUT_RECORD *ir)
 
static unsigned int win32_keyboard_get (struct win32_signal *ws)
 
void win32_signal_close (struct win32_signal *ws)
 
bool win32_service_interrupt (struct win32_signal *ws)
 
int win32_signal_get (struct win32_signal *ws)
 
void win32_pause (struct win32_signal *ws)
 
void window_title_clear (struct window_title *wt)
 
void window_title_save (struct window_title *wt)
 
void window_title_restore (const struct window_title *wt)
 
void window_title_generate (const char *title)
 
void semaphore_clear (struct semaphore *s)
 
void semaphore_open (struct semaphore *s, const char *name)
 
bool semaphore_lock (struct semaphore *s, int timeout_milliseconds)
 
void semaphore_release (struct semaphore *s)
 
void semaphore_close (struct semaphore *s)
 
void netcmd_semaphore_init (void)
 
void netcmd_semaphore_close (void)
 
void netcmd_semaphore_lock (void)
 
void netcmd_semaphore_release (void)
 
static char * env_block (const struct env_set *es)
 
static WCHAR * wide_cmd_line (const struct argv *a, struct gc_arena *gc)
 
int openvpn_execve (const struct argv *a, const struct env_set *es, const unsigned int flags)
 
void fork_to_self (const char *cmdline)
 
char * get_win_sys_path (void)
 
void set_win_sys_path (const char *newpath, struct env_set *es)
 
void set_win_sys_path_via_env (struct env_set *es)
 
static bool win_block_dns_service (bool add, int index, const HANDLE pipe)
 
static void block_dns_msg_handler (DWORD err, const char *msg)
 
bool win_wfp_block_dns (const NET_IFINDEX index, const HANDLE msg_channel)
 
bool win_wfp_uninit (const NET_IFINDEX index, const HANDLE msg_channel)
 
int win32_version_info (void)
 
static void win32_get_arch (arch_t *process_arch, arch_t *host_arch)
 
static void win32_print_arch (arch_t arch, struct buffer *out)
 
const char * win32_version_string (struct gc_arena *gc, bool add_name)
 
bool send_msg_iservice (HANDLE pipe, const void *data, size_t size, ack_message_t *ack, const char *context)
 
bool openvpn_swprintf (wchar_t *const str, const size_t size, const wchar_t *const format,...)
 
static BOOL get_install_path (WCHAR *path, DWORD size)
 
void win32_sleep (const int n)
 

Variables

static HANDLE m_hEngineHandle = NULL
 
static int tap_metric_v4 = -1
 
static int tap_metric_v6 = -1
 
static struct WSAData wsa_state
 
static bool pause_exit_enabled = false
 
struct win32_signal win32_signal
 
struct window_title window_title
 
struct semaphore netcmd_semaphore
 
static char * win_sys_path = NULL
 

Enumeration Type Documentation

◆ arch_t

enum arch_t
Enumerator
ARCH_X86 
ARCH_AMD64 
ARCH_ARM64 
ARCH_NATIVE 
ARCH_UNKNOWN 

Definition at line 1307 of file win32.c.

Function Documentation

◆ block_dns_msg_handler()

static void block_dns_msg_handler ( DWORD  err,
const char *  msg 
)
static

Definition at line 1177 of file win32.c.

References gc_free(), gc_new(), M_INFO, M_WARN, msg, and strerror_win32().

Referenced by win_wfp_block_dns().

◆ close_net_event_win32()

void close_net_event_win32 ( struct rw_handle event,
socket_descriptor_t  sd,
unsigned int  flags 
)

◆ env_block()

static char* env_block ( const struct env_set es)
static

◆ fork_to_self()

void fork_to_self ( const char *  cmdline)

Definition at line 1070 of file win32.c.

References CLEAR, M_ERRNO, M_WARN, msg, status, and string_alloc().

Referenced by fork_dhcp_action(), and fork_register_dns_action().

◆ get_install_path()

static BOOL get_install_path ( WCHAR *  path,
DWORD  size 
)
static

Definition at line 1501 of file win32.c.

References openvpn_swprintf(), PACKAGE_NAME, and status.

Referenced by set_openssl_env_vars().

◆ get_win_sys_path()

char* get_win_sys_path ( void  )

◆ init_net_event_win32()

void init_net_event_win32 ( struct rw_handle event,
long  network_events,
socket_descriptor_t  sd,
unsigned int  flags 
)

◆ init_security_attributes_allow_all()

bool init_security_attributes_allow_all ( struct security_attributes obj)

◆ init_win32()

void init_win32 ( void  )

Definition at line 106 of file win32.c.

References M_ERR, msg, set_openssl_env_vars(), win32_signal_clear(), window_title_clear(), and wsa_state.

Referenced by init_static().

◆ keyboard_input_available()

static bool keyboard_input_available ( struct win32_signal ws)
static

◆ keyboard_ir_to_key()

static unsigned int keyboard_ir_to_key ( INPUT_RECORD *  ir)
static

Definition at line 556 of file win32.c.

Referenced by win32_keyboard_get().

◆ net_event_win32_close()

void net_event_win32_close ( struct net_event_win32 ne)

◆ net_event_win32_init()

void net_event_win32_init ( struct net_event_win32 ne)

Definition at line 321 of file win32.c.

References CLEAR, net_event_win32::sd, and SOCKET_UNDEFINED.

Referenced by man_connection_init(), and net_event_win32_close().

◆ net_event_win32_reset()

void net_event_win32_reset ( struct net_event_win32 ne)

◆ net_event_win32_reset_write()

void net_event_win32_reset_write ( struct net_event_win32 ne)

◆ net_event_win32_start()

void net_event_win32_start ( struct net_event_win32 ne,
long  network_events,
socket_descriptor_t  sd 
)

◆ net_event_win32_stop()

void net_event_win32_stop ( struct net_event_win32 ne)

◆ netcmd_semaphore_close()

void netcmd_semaphore_close ( void  )

Definition at line 849 of file win32.c.

References netcmd_semaphore, and semaphore_close().

Referenced by uninit_win32().

◆ netcmd_semaphore_init()

void netcmd_semaphore_init ( void  )

Definition at line 843 of file win32.c.

References netcmd_semaphore, PACKAGE, and semaphore_open().

Referenced by netcmd_semaphore_lock().

◆ netcmd_semaphore_lock()

void netcmd_semaphore_lock ( void  )

◆ netcmd_semaphore_release()

void netcmd_semaphore_release ( void  )

◆ openvpn_execve()

int openvpn_execve ( const struct argv a,
const struct env_set es,
const unsigned int  flags 
)

Definition at line 998 of file win32.c.

Referenced by openvpn_execve_check().

◆ openvpn_swprintf()

bool openvpn_swprintf ( wchar_t *const  str,
const size_t  size,
const wchar_t *const  format,
  ... 
)

◆ overlapped_io_close()

void overlapped_io_close ( struct overlapped_io o)

◆ overlapped_io_init()

void overlapped_io_init ( struct overlapped_io o,
const struct frame frame,
BOOL  event_state 
)

◆ overlapped_io_state_ascii()

char* overlapped_io_state_ascii ( const struct overlapped_io o)

Definition at line 199 of file win32.c.

References overlapped_io::iostate, IOSTATE_IMMEDIATE_RETURN, IOSTATE_INITIAL, and IOSTATE_QUEUED.

Referenced by socket_stat(), and tun_stat().

◆ reset_net_event_win32()

long reset_net_event_win32 ( struct rw_handle event,
socket_descriptor_t  sd 
)

Definition at line 259 of file win32.c.

References M_ERRNO, M_FATAL, msg, and rw_handle::read.

Referenced by net_event_win32_reset(), and socket_reset_listen_persistent().

◆ semaphore_clear()

void semaphore_clear ( struct semaphore s)

Definition at line 743 of file win32.c.

References CLEAR.

◆ semaphore_close()

void semaphore_close ( struct semaphore s)

◆ semaphore_lock()

bool semaphore_lock ( struct semaphore s,
int  timeout_milliseconds 
)

◆ semaphore_open()

void semaphore_open ( struct semaphore s,
const char *  name 
)

◆ semaphore_release()

void semaphore_release ( struct semaphore s)

◆ send_msg_iservice()

bool send_msg_iservice ( HANDLE  pipe,
const void *  data,
size_t  size,
ack_message_t ack,
const char *  context 
)

◆ set_openssl_env_vars()

static void set_openssl_env_vars ( )
static

Set OpenSSL environment variables to a safe directory.

Definition at line 1524 of file win32.c.

References get_install_path(), openvpn_swprintf(), and SIZE.

Referenced by init_win32().

◆ set_pause_exit_win32()

void set_pause_exit_win32 ( void  )

Definition at line 143 of file win32.c.

References pause_exit_enabled.

Referenced by add_option().

◆ set_win_sys_path()

void set_win_sys_path ( const char *  newpath,
struct env_set es 
)

Definition at line 1117 of file win32.c.

References es, setenv_str(), string_alloc(), SYS_PATH_ENV_VAR_NAME, and win_sys_path.

Referenced by add_option(), and set_win_sys_path_via_env().

◆ set_win_sys_path_via_env()

void set_win_sys_path_via_env ( struct env_set es)

Definition at line 1125 of file win32.c.

References es, M_ERR, M_FATAL, msg, set_win_sys_path(), status, and SYS_PATH_ENV_VAR_NAME.

Referenced by openvpn_main().

◆ uninit_win32()

void uninit_win32 ( void  )

◆ wide_cmd_line()

static WCHAR* wide_cmd_line ( const struct argv a,
struct gc_arena gc 
)
static

◆ win32_get_arch()

static void win32_get_arch ( arch_t process_arch,
arch_t host_arch 
)
static

Definition at line 1316 of file win32.c.

References ARCH_AMD64, ARCH_ARM64, ARCH_NATIVE, ARCH_UNKNOWN, and ARCH_X86.

Referenced by win32_version_string().

◆ win32_keyboard_get()

static unsigned int win32_keyboard_get ( struct win32_signal ws)
static

◆ win32_pause()

void win32_pause ( struct win32_signal ws)

◆ win32_print_arch()

static void win32_print_arch ( arch_t  arch,
struct buffer out 
)
static

Definition at line 1383 of file win32.c.

References ARCH_AMD64, ARCH_ARM64, ARCH_UNKNOWN, ARCH_X86, and buf_printf().

Referenced by win32_version_string().

◆ win32_service_interrupt()

bool win32_service_interrupt ( struct win32_signal ws)

◆ win32_signal_clear()

void win32_signal_clear ( struct win32_signal ws)

Definition at line 444 of file win32.c.

References CLEAR.

Referenced by init_win32().

◆ win32_signal_close()

void win32_signal_close ( struct win32_signal ws)

◆ win32_signal_get()

int win32_signal_get ( struct win32_signal ws)

◆ win32_signal_open()

void win32_signal_open ( struct win32_signal ws,
int  force,
const char *  exit_event_name,
bool  exit_event_initial_state 
)

◆ win32_sleep()

void win32_sleep ( const int  n)

Definition at line 1566 of file win32.c.

References HANDLE_DEFINED, win32_signal::in, now, rw_handle::read, status, update_time(), and win32_signal_get().

Referenced by management_sleep().

◆ win32_version_info()

int win32_version_info ( void  )

Definition at line 1272 of file win32.c.

References M_FATAL, msg, WIN_10, WIN_7, WIN_8, WIN_8_1, WIN_VISTA, and WIN_XP.

Referenced by netsh_ifconfig_options(), netsh_set_dns6_servers(), and win32_version_string().

◆ win32_version_string()

const char* win32_version_string ( struct gc_arena gc,
bool  add_name 
)

◆ win_block_dns_service()

static bool win_block_dns_service ( bool  add,
int  index,
const HANDLE  pipe 
)
static

◆ win_ctrl_handler()

static bool WINAPI win_ctrl_handler ( DWORD  signum)
static

◆ win_trigger_event()

static void win_trigger_event ( struct win32_signal ws)
static

◆ win_wfp_block_dns()

bool win_wfp_block_dns ( const NET_IFINDEX  index,
const HANDLE  msg_channel 
)

◆ win_wfp_uninit()

bool win_wfp_uninit ( const NET_IFINDEX  index,
const HANDLE  msg_channel 
)

◆ window_title_clear()

void window_title_clear ( struct window_title wt)

Definition at line 695 of file win32.c.

References CLEAR.

Referenced by init_win32().

◆ window_title_generate()

void window_title_generate ( const char *  title)

Definition at line 727 of file win32.c.

References alloc_buf_gc(), BSTR, buf_printf(), gc_free(), gc_new(), PACKAGE_NAME, and PACKAGE_VERSION.

Referenced by pre_setup().

◆ window_title_restore()

void window_title_restore ( const struct window_title wt)

Definition at line 718 of file win32.c.

References window_title::old_window_title, and window_title::saved.

Referenced by uninit_win32().

◆ window_title_save()

void window_title_save ( struct window_title wt)

Definition at line 701 of file win32.c.

References window_title::old_window_title, and window_title::saved.

Referenced by pre_setup().

Variable Documentation

◆ m_hEngineHandle

HANDLE m_hEngineHandle = NULL
static

Definition at line 55 of file win32.c.

Referenced by win_wfp_block_dns(), and win_wfp_uninit().

◆ netcmd_semaphore

struct semaphore netcmd_semaphore

◆ pause_exit_enabled

bool pause_exit_enabled = false
static

Definition at line 71 of file win32.c.

Referenced by set_pause_exit_win32(), and uninit_win32().

◆ tap_metric_v4

int tap_metric_v4 = -1
static

Definition at line 60 of file win32.c.

Referenced by win_wfp_block_dns(), and win_wfp_uninit().

◆ tap_metric_v6

int tap_metric_v6 = -1
static

Definition at line 61 of file win32.c.

Referenced by win_wfp_block_dns(), and win_wfp_uninit().

◆ win32_signal

Definition at line 79 of file win32.c.

◆ win_sys_path

char* win_sys_path = NULL
static

Definition at line 97 of file win32.c.

Referenced by get_win_sys_path(), set_win_sys_path(), and uninit_win32().

◆ window_title

Definition at line 85 of file win32.c.

◆ wsa_state

struct WSAData wsa_state
static

Definition at line 66 of file win32.c.

Referenced by init_win32().