OpenVPN 3 Core Library
Loading...
Searching...
No Matches
openvpn::TunWin::Dns< REG, NETAPI > Class Template Reference

Manage DNS search suffixes for Windows. More...

#include <dns.hpp>

Classes

class  ActionApply
 
class  ActionCreate
 
class  ActionDelete
 

Public Member Functions

 OPENVPN_EXCEPTION (dns_error)
 

Static Public Member Functions

static void set_search_domains (const std::string &itf_name, const std::string &domains)
 Add DNS search domain(s)
 
static void reset_search_domains (typename REG::Key &list_key)
 Reset the DNS "SearchList" to its original value.
 
static void remove_search_domains (const std::string &itf_name, const std::string &domains)
 Remove domain suffix(es) from the system.
 

Static Private Member Functions

static std::pair< typename REG::Key, bool > open_searchlist_key ()
 Return the Key for the DNS domain "SearchList" value.
 
static bool initial_searchlist_exists (typename REG::Key &key)
 Check if a initial list had already been created.
 
static bool set_initial_searchlist (typename REG::Key &key, const std::wstring &searchlist)
 
static bool set_initial_searchlist_from_existing (typename REG::Key &key)
 Set the initial searchlist from the existing search list.
 
static bool set_initial_searchlist_from_domains (typename REG::Key &key)
 
static bool set_itf_domain_suffix (const std::string &itf_name, const std::wstring &domain)
 Set interface specific domain suffix.
 
static bool add_to_searchlist (typename REG::Key &key, const std::wstring &domains)
 Append domain suffixes to an existing search list.
 

Static Private Attributes

static constexpr std::array< PCWSTR, 2 > searchlist_subkeys
 

Detailed Description

template<typename REG, typename NETAPI>
class openvpn::TunWin::Dns< REG, NETAPI >

Manage DNS search suffixes for Windows.

Template Parameters
REGRegistry abstraction class to use
NETAPINetwork related Win32 API class to use

Definition at line 65 of file dns.hpp.

Member Function Documentation

◆ add_to_searchlist()

template<typename REG , typename NETAPI >
static bool openvpn::TunWin::Dns< REG, NETAPI >::add_to_searchlist ( typename REG::Key &  key,
const std::wstring &  domains 
)
inlinestaticprivate

Append domain suffixes to an existing search list.

Parameters
keythe registry key to modify values under
domainsdomain suffixes as comma separated string
Returns
bool to indicate success or failure

Definition at line 253 of file dns.hpp.

Here is the caller graph for this function:

◆ initial_searchlist_exists()

template<typename REG , typename NETAPI >
static bool openvpn::TunWin::Dns< REG, NETAPI >::initial_searchlist_exists ( typename REG::Key &  key)
inlinestaticprivate

Check if a initial list had already been created.

Parameters
keykey to look under for the initial list
Returns
bool to indicate if the initial list is already present

Definition at line 114 of file dns.hpp.

Here is the caller graph for this function:

◆ open_searchlist_key()

template<typename REG , typename NETAPI >
static std::pair< typename REG::Key, bool > openvpn::TunWin::Dns< REG, NETAPI >::open_searchlist_key ( )
inlinestaticprivate

Return the Key for the DNS domain "SearchList" value.

It also returns a boolean value, telling whether a SearchList already exists under the returned registry key.

Returns
std::pair<REG::Key, bool> the search list key and a boolean telling if a list exists

Definition at line 86 of file dns.hpp.

Here is the caller graph for this function:

◆ OPENVPN_EXCEPTION()

template<typename REG , typename NETAPI >
openvpn::TunWin::Dns< REG, NETAPI >::OPENVPN_EXCEPTION ( dns_error  )

◆ remove_search_domains()

template<typename REG , typename NETAPI >
static void openvpn::TunWin::Dns< REG, NETAPI >::remove_search_domains ( const std::string &  itf_name,
const std::string &  domains 
)
inlinestatic

Remove domain suffix(es) from the system.

If a search list exists, it is restored to the previous state. The adapter domain suffix is also emptied. And temporary values from the registry are removed if they are no longer needed.

Parameters
itf_namealias name of the interface the suffix is removed from
domainsa comma separated list of domain names to be removed

Definition at line 354 of file dns.hpp.

Here is the caller graph for this function:

◆ reset_search_domains()

template<typename REG , typename NETAPI >
static void openvpn::TunWin::Dns< REG, NETAPI >::reset_search_domains ( typename REG::Key &  list_key)
inlinestatic

Reset the DNS "SearchList" to its original value.

Looks for "OriginalSearchList" value as the one to reset to. If it doesn't exists resets to the empty value, which is interpreted as no search list.

Parameters
list_keykey in the registry to reset the values under

Definition at line 331 of file dns.hpp.

Here is the caller graph for this function:

◆ set_initial_searchlist()

template<typename REG , typename NETAPI >
static bool openvpn::TunWin::Dns< REG, NETAPI >::set_initial_searchlist ( typename REG::Key &  key,
const std::wstring &  searchlist 
)
inlinestaticprivate

Prepare DNS domain "SearchList" registry value, so additional VPN domains can be added and its original state can be restored when the VPN disconnects.

Parameters
keythe registry key to modify values under
searchliststring of comma separated domains to use as the list
Returns
bool indicates whether the list is stored successfully

Definition at line 130 of file dns.hpp.

Here is the caller graph for this function:

◆ set_initial_searchlist_from_domains()

template<typename REG , typename NETAPI >
static bool openvpn::TunWin::Dns< REG, NETAPI >::set_initial_searchlist_from_domains ( typename REG::Key &  key)
inlinestaticprivate

Create a initial DNS search list if it does not exist already

Parameters
keythe registry key to modify values under
Returns
bool to indicate creation success or failure

Definition at line 176 of file dns.hpp.

Here is the caller graph for this function:

◆ set_initial_searchlist_from_existing()

template<typename REG , typename NETAPI >
static bool openvpn::TunWin::Dns< REG, NETAPI >::set_initial_searchlist_from_existing ( typename REG::Key &  key)
inlinestaticprivate

Set the initial searchlist from the existing search list.

Parameters
keythe registry key to modify values under
Returns
bool indicates whether the list is stored successfully

Definition at line 152 of file dns.hpp.

Here is the caller graph for this function:

◆ set_itf_domain_suffix()

template<typename REG , typename NETAPI >
static bool openvpn::TunWin::Dns< REG, NETAPI >::set_itf_domain_suffix ( const std::string &  itf_name,
const std::wstring &  domain 
)
inlinestaticprivate

Set interface specific domain suffix.

Parameters
itf_nameinterface alias name to set the domain suffix for
domaindomain suffix to set as wide character string
Returns
bool to indicate success or failure setting the domain suffix

Definition at line 226 of file dns.hpp.

Here is the caller graph for this function:

◆ set_search_domains()

template<typename REG , typename NETAPI >
static void openvpn::TunWin::Dns< REG, NETAPI >::set_search_domains ( const std::string &  itf_name,
const std::string &  domains 
)
inlinestatic

Add DNS search domain(s)

Extend the list of DNS search domains present on the system. If domains is only a single domain (no comma) and there currently is no search list defined on the system, a interface specific domain suffix is used instead of generating a new search list.

Parameters
itf_namealias name of the interface a single domain is set for
domainsa comma separated list of domain names

Definition at line 285 of file dns.hpp.

Here is the caller graph for this function:

Member Data Documentation

◆ searchlist_subkeys

template<typename REG , typename NETAPI >
constexpr std::array<PCWSTR, 2> openvpn::TunWin::Dns< REG, NETAPI >::searchlist_subkeys
staticconstexprprivate
Initial value:
{
LR"(SOFTWARE\Policies\Microsoft\WindowsNT\DNSClient)",
LR"(System\CurrentControlSet\Services\TCPIP\Parameters)"}

Registry locations the DNS search domains list can be stored in. When the first key exists and it has domains in the "SearchList" value, then these GPO provided domains will be used as suffixes, otherwise the manually created ones in the second key will be used (if they exist).

Definition at line 73 of file dns.hpp.


The documentation for this class was generated from the following file: