OpenVPN
common.c File Reference
#include "service.h"
#include "validate.h"
#include "eventmsg.h"
#include <pathcch.h>
Include dependency graph for common.c:

Go to the source code of this file.

Functions

static DWORD GetRegString (HKEY key, LPCWSTR value, LPWSTR data, DWORD size, LPCWSTR default_value)
static BOOL ensure_trailing_backslash (PWSTR dir, size_t size)
 Make sure that a dir path ends with a backslash.
DWORD GetOpenvpnSettings (settings_t *s)
LPCWSTR GetLastErrorText (void)
DWORD MsgToEventLog (DWORD flags, LPCWSTR format,...)
wchar_t * utf8to16_size (const char *utf8, int size)
 Convert a UTF-8 string to UTF-16.
const wchar_t * get_win_sys_path (void)

Variables

LPCWSTR service_instance = L""
static wchar_t win_sys_path [MAX_PATH]

Function Documentation

◆ ensure_trailing_backslash()

BOOL ensure_trailing_backslash ( PWSTR dir,
size_t size )
static

Make sure that a dir path ends with a backslash.

If it doesn't, a \ is added to the end of the path, if there's room in the buffer.

Parameters
dirpointer to the wide dir path string buffer
sizemaximum number of wide chars the dir path buffer
Returns
BOOL to indicate success or failure

Definition at line 69 of file common.c.

Referenced by GetOpenvpnSettings().

◆ get_win_sys_path()

const wchar_t * get_win_sys_path ( void )

Definition at line 313 of file common.c.

References win_sys_path.

◆ GetLastErrorText()

LPCWSTR GetLastErrorText ( void )

Definition at line 218 of file common.c.

Referenced by CmdInstallServices(), CmdRemoveServices(), CmdStartService(), and MsgToEventLog().

◆ GetOpenvpnSettings()

◆ GetRegString()

DWORD GetRegString ( HKEY key,
LPCWSTR value,
LPWSTR data,
DWORD size,
LPCWSTR default_value )
static

Definition at line 34 of file common.c.

References _L, M_SYSERR, MsgToEventLog(), service_instance, and status.

Referenced by GetOpenvpnSettings().

◆ MsgToEventLog()

◆ utf8to16_size()

wchar_t * utf8to16_size ( const char * utf8,
int size )

Convert a UTF-8 string to UTF-16.

The size parameter can be used to convert strings which contain inline NUL characters, like MULTI_SZ strings used as values in the registry do, or (sub)strings that are not zero terminated. If size is -1 the length of the string is determined automatically by the WIN32 API. Make sure you pass a terminated string or else bad things will happen. Note that the size you pass should always include the terminating zero as well.

If the returned string is not NULL it must be freed by the caller.

Parameters
utf8const string to be converted
sizethe size of the string
Returns
wchar_t* heap allocated result string

Definition at line 296 of file common.c.

Referenced by SetNrptRules(), and utf8to16().

Variable Documentation

◆ service_instance

LPCWSTR service_instance = L""

◆ win_sys_path

wchar_t win_sys_path[MAX_PATH]
static

Definition at line 31 of file common.c.