From: "d12fk (Code Review)" Date: Fri, 7 Mar 2025 02:39:42 +0000 References: Reply-To: heiko@...515..., arne-openvpn@...1227..., openvpn-devel@lists.sourceforge.net, frank@...2641... Message-ID: <2609ea882d125e4e86450ea68da0edcaa7823587-HTML@...2715...> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Disposition: inline Content-Type: multipart/alternative; boundary="tgoUKK0UmC0="; charset=UTF-8 Subject: [Openvpn-devel] [M] Change in openvpn[master]: win: match search domains when creating exclude rules List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: plaisthos , flichtenheld Cc: openvpn-devel --tgoUKK0UmC0= Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Attention is currently required from: flichtenheld, plaisthos. Hello plaisthos, flichtenheld, I'd like you to do a code review. Please visit http://gerrit.openvpn.net/c/openvpn/+/905?usp=3Demail to review the following change. Change subject: win: match search domains when creating exclude rules ...................................................................... win: match search domains when creating exclude rules Compare local domains for exclude rules to search domains and skip matching ones. This prevents the creation of exclude rules when the server indicates that the domain should be resolved via the VPN, by pushing the search domain. Change-Id: I4919af2b845a47787c08f454b108ef376ea5c0f6 Signed-off-by: Heiko Hund --- M src/openvpnserv/interactive.c 1 file changed, 56 insertions(+), 24 deletions(-) git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/05/905/1 diff --git a/src/openvpnserv/interactive.c b/src/openvpnserv/interactive.c index 6097cd0..f725199 100644 --- a/src/openvpnserv/interactive.c +++ b/src/openvpnserv/interactive.c @@ -2163,12 +2163,14 @@ * In case of an error or if no domains are found for the interface * \p size is set to 0 and the contents of \p domains are invalid. * Note that the domains could have been set by DHCP or manually. + * Note that domains are ignored if they match a pushed search domain. * - * @param itf HKEY of the interface to read from - * @param domains PWSTR buffer to return the domain(s) in - * @param size pointer to size of the domains buffer in bytes. Will= be - * set to the size of the string returned, including - * the terminating zeros or 0. + * @param itf HKEY of the interface to read from + * @param search_domains optional list of search domains + * @param domains PWSTR buffer to return the domain(s) in + * @param size pointer to size of the domains buffer in bytes.= Will be + * set to the size of the string returned, includi= ng + * the terminating zeros or 0. * * @return LSTATUS NO_ERROR if the domain suffix(es) were read successfull= y, * ERROR_FILE_NOT_FOUND if no domain was found for the interface, @@ -2176,7 +2178,7 @@ * any other error indicates an error while reading from the regis= try. */ static LSTATUS -GetItfDnsDomains(HKEY itf, PWSTR domains, PDWORD size) +GetItfDnsDomains(HKEY itf, PCWSTR search_domains, PWSTR domains, PDWORD si= ze) { if (domains =3D=3D NULL || size =3D=3D 0) { @@ -2209,9 +2211,29 @@ *comma =3D '\0'; } + /* Ignore itf domains which match pushed search domains */ + size_t domain_len =3D wcslen(pos); + PCWSTR match =3D wcsstr(search_domains, pos); + if (match && (match =3D=3D search_domains || *(match - 1) = =3D=3D ',') + && (*(match + domain_len) =3D=3D ',' || *(match + doma= in_len) =3D=3D '\0')) + { + if (comma) + { + pos =3D comma + 1; + continue; + } + else + { + /* This was the last domain */ + *pos =3D '\0'; + *size +=3D 1; + return wcslen(domains) ? NO_ERROR : ERROR_FILE_NOT= _FOUND; + } + } + /* Check for enough space to convert this domain */ + domain_len +=3D 1; /* leading dot */ size_t converted_size =3D pos - domains; - size_t domain_len =3D wcslen(pos) + 1; size_t domain_size =3D domain_len * one_glyph; size_t extra_size =3D 2 * one_glyph; if (converted_size + domain_size + extra_size > buf_size) @@ -2292,11 +2314,12 @@ * needed so that local DNS keeps working even when a catch all NRPT rule = is * installed by a VPN connection. * - * @param data pointer to the data structures the values are return= ed in - * @param data_size number of exclude data structures pointed to + * @param search_domains optional list of search domains + * @param data pointer to the data structures the values are r= eturned in + * @param data_size number of exclude data structures pointed to */ static void -GetNrptExcludeData(nrpt_exclude_data_t *data, size_t data_size) +GetNrptExcludeData(PCWSTR search_domains, nrpt_exclude_data_t *data, size_= t data_size) { HKEY v4_itfs =3D INVALID_HANDLE_VALUE; HKEY v6_itfs =3D INVALID_HANDLE_VALUE; @@ -2342,7 +2365,7 @@ /* Get the DNS domain(s) for exclude routing */ data[i].domains_size =3D sizeof(data[0].domains); memset(data[i].domains, 0, data[i].domains_size); - err =3D GetItfDnsDomains(v4_itf, data[i].domains, &data[i].domains= _size); + err =3D GetItfDnsDomains(v4_itf, search_domains, data[i].domains, = &data[i].domains_size); if (err) { if (err !=3D ERROR_FILE_NOT_FOUND) @@ -2504,15 +2527,16 @@ * local resolution of names is not interfered with in case the VPN resolv= es * all names. * - * @param nrpt_key the registry key to set the rules under - * @param ovpn_pid the PID of the openvpn process + * @param nrpt_key the registry key to set the rules under + * @param ovpn_pid the PID of the openvpn process + * @param search_domains optional list of search domains */ static void -SetNrptExcludeRules(HKEY nrpt_key, DWORD ovpn_pid) +SetNrptExcludeRules(HKEY nrpt_key, DWORD ovpn_pid, PCWSTR search_domains) { nrpt_exclude_data_t data[8]; /* data from up to 8 interfaces */ memset(data, 0, sizeof(data)); - GetNrptExcludeData(data, _countof(data)); + GetNrptExcludeData(search_domains, data, _countof(data)); unsigned n =3D 0; for (int i =3D 0; i < _countof(data); ++i) @@ -2534,17 +2558,18 @@ /** * Set NRPT rules for a openvpn process * - * @param nrpt_key the registry key to set the rules under - * @param addresses name server addresses - * @param domains optional list of split routing domains - * @param dnssec boolean whether DNSSEC is to be used - * @param ovpn_pid the PID of the openvpn process + * @param nrpt_key the registry key to set the rules under + * @param addresses name server addresses + * @param domains optional list of split routing domains + * @param search_domains optional list of search domains + * @param dnssec boolean whether DNSSEC is to be used + * @param ovpn_pid the PID of the openvpn process * * @return NO_ERROR on success, or a Windows error code */ static DWORD -SetNrptRules(HKEY nrpt_key, const nrpt_address_t *addresses, - const char *domains, BOOL dnssec, DWORD ovpn_pid) +SetNrptRules(HKEY nrpt_key, const nrpt_address_t *addresses, const char *d= omains, + const char *search_domains, BOOL dnssec, DWORD ovpn_pid) { DWORD err =3D NO_ERROR; PWSTR wide_domains =3D L".\0"; /* DNS route everything by default */ @@ -2573,7 +2598,14 @@ } else { - SetNrptExcludeRules(nrpt_key, ovpn_pid); + PWSTR wide_search_domains; + wide_search_domains =3D utf8to16(search_domains); + if (!wide_search_domains) + { + return ERROR_OUTOFMEMORY; + } + SetNrptExcludeRules(nrpt_key, ovpn_pid, wide_search_domains); + free(wide_search_domains); } /* Create address string list */ @@ -2833,7 +2865,7 @@ /* Set NRPT rules */ BOOL dnssec =3D (msg->flags & nrpt_dnssec) !=3D 0; - err =3D SetNrptRules(key, msg->addresses, msg->resolve_domains, dnssec= , ovpn_pid); + err =3D SetNrptRules(key, msg->addresses, msg->resolve_domains, msg->s= earch_domains, dnssec, ovpn_pid); if (err) { goto out; -- To view, visit http://gerrit.openvpn.net/c/openvpn/+/905?usp=3Demail To unsubscribe, or for help writing mail filters, visit http://gerrit.openv= pn.net/settings Gerrit-Project: openvpn Gerrit-Branch: master Gerrit-Change-Id: I4919af2b845a47787c08f454b108ef376ea5c0f6 Gerrit-Change-Number: 905 Gerrit-PatchSet: 1 Gerrit-Owner: d12fk Gerrit-Reviewer: flichtenheld Gerrit-Reviewer: plaisthos Gerrit-CC: openvpn-devel Gerrit-Attention: plaisthos Gerrit-Attention: flichtenheld Gerrit-MessageType: newchange --tgoUKK0UmC0= Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable

Attention is currently required from: flichtenheld, plaisthos.

d12fk would like plaisthos and flichtenheld to review t= his change.

Vi= ew Change

win: match search domains when creating exclude rules

= Compare local domains for exclude rules to search domains and skip
match= ing ones. This prevents the creation of exclude rules when the
server in= dicates that the domain should be resolved via the VPN, by
pushing the s= earch domain.

Change-Id: I4919af2b845a47787c08f454b108ef376ea5c0f6Signed-off-by: Heiko Hund <heiko@...2662...>
---
M src/openvp= nserv/interactive.c
1 file changed, 56 insertions(+), 24 deletions(-)
git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/05/905=
/1
diff --git a/src/openvpnserv/interactive.c b/src/openvpnserv/int=
eractive.c
index 6097cd0..f725199 100644
--= - a/src/openvpnserv/interactive.c
+++ b/src/openvpnserv/int= eractive.c
@@ -2163,12 +2163,14 @@
* In c= ase of an error or if no domains are found for the interface
* \p size is set to 0 and the contents of \p domains are invalid.
* Note that the domains could have been set by DHCP or manuall= y.
+ * Note that doma= ins are ignored if they match a pushed search domain.
*
- * @param itf H= KEY of the interface to read from
- * @param domains PWSTR buffer to return the domain(s) in
- * @param size p= ointer to size of the domains buffer in bytes. Will be
- * set to the size of t= he string returned, including
- * the terminating zeros or 0.
+ * @param itf HKEY of th= e interface to read from
+ * @param search_domains optional list of search domains
<= span style=3D"color: hsl(120, 100%, 40%);">+ * @param domains PWST= R buffer to return the domain(s) in

+ * @param size pointer to size of the domains b= uffer in bytes. Will be
+ * set to the size of the string returned, incl= uding
+ * = the terminating zeros or 0.
*
* @return LSTATUS NO_ERROR if the domain suffix(es) were read successfu= lly,

* ERROR_FILE_NOT_FOUND if no domain was foun= d for the interface,
@@ -2176,7 +2178,7 @@
= * any other error indicates an error while reading from the regis= try.
*/
static LSTATUS
-GetItfDnsDomains(HKEY itf, PWSTR domain= s, PDWORD size)
+GetI= tfDnsDomains(HKEY itf, PCWSTR search_domains, PWSTR domains, PDWORD size)
{
if (domains =3D=3D NULL || size =3D= =3D 0)
{
@@ -2209,9 +2211,29 @@=
*comma =3D '\0';
= }

+ /* Ignore itf domains which match pushed sear= ch domains */
+ = size_t domain_len =3D wcslen(pos);
+ PCWSTR match =3D wcsstr(search_dom= ains, pos);
+ = if (match && (match =3D=3D search_domains || *(match - 1) = =3D=3D ',')
+= && (*(match + domain_len) =3D=3D ',' ||= *(match + domain_len) =3D=3D '\0'))
+ {
+ if (comma)
+ {
+ pos =3D comma += 1;
+ = continue;
+ = }
+= else
+ {
+ /* This was the last domain */
+ *pos =3D = '\0';

+ = *size +=3D 1;
+ return wcslen(domains) ? NO_ERROR : ERR= OR_FILE_NOT_FOUND;
+ = }
= + }
+<= /span>
/* Check for enough space to convert this = domain */
+ = domain_len +=3D 1; /* leading dot */
= size_t converted_size =3D pos - domains;
- size_t domain_len =3D wcslen(pos) + 1;<= /span>
size_t domain_size =3D domain_len * one_gl= yph;
size_t extra_size =3D 2 * one_glyph;<= /span>
if (converted_size + domain_size + extra_s= ize > buf_size)
@@ -2292,11 +2314,12 @@
= * needed so that local DNS keeps working even when a catch all NRPT rule = is
* installed by a VPN connection.
*
- * @param data p= ointer to the data structures the values are returned in
- * @param data_size number of exclude = data structures pointed to
+ * @param search_domains optional list of search domains+ * @param data po= inter to the data structures the values are returned in
+ * @param data_size number of ex= clude data structures pointed to
*/
stat= ic void
-GetNrptExclude= Data(nrpt_exclude_data_t *data, size_t data_size)
+GetNrptExcludeData(PCWSTR search_domains, nrp= t_exclude_data_t *data, size_t data_size)
{
HKEY v4_itfs =3D INVALID_HANDLE_VALUE;

HKEY v6_= itfs =3D INVALID_HANDLE_VALUE;
@@ -2342,7 +2365,7 @@=
/* Get the DNS domain(s) for exclude routing */ data[i].domains_size =3D sizeof(data[0].domains); memset(data[i].domains, 0, data[i].domains_size);- err =3D GetItfDnsDomai= ns(v4_itf, data[i].domains, &data[i].domains_size);
+ err =3D GetItfDnsDomains(v4_itf= , search_domains, data[i].domains, &data[i].domains_size);
if (err)

{
= if (err !=3D ERROR_FILE_NOT_FOUND)
@@ -2504,15 +2527,16 = @@
* local resolution of names is not interfered with in = case the VPN resolves
* all names.
*
- * @param nrpt_key th= e registry key to set the rules under
- * @param ovpn_pid the PID of the openvpn process=
+ * @param nrpt_key = the registry key to set the rules under
+ * @param ovpn_pid the PID of the openvpn proc= ess
+ * @param searc= h_domains optional list of search domains
*/
<= span> static void

-SetN= rptExcludeRules(HKEY nrpt_key, DWORD ovpn_pid)
+SetNrptExcludeRules(HKEY nrpt_key, DWORD ovpn_pi= d, PCWSTR search_domains)
{
nrpt_excl= ude_data_t data[8]; /* data from up to 8 interfaces */
= memset(data, 0, sizeof(data));
- GetNrptExcludeData(data, _countof(data));
+ GetNrptExcludeData(search_domains, = data, _countof(data));

unsigned n = =3D 0;
for (int i =3D 0; i < _countof(data); ++i)
@@ -2534,17 +2558,18 @@
/**
* Set NRPT rules for a openvpn process

*
- * @param nrpt_key the registry = key to set the rules under

- * @param addresses name server addresses
- * @param domains optional list of split rou= ting domains
- * @param= dnssec boolean whether DNSSEC is to be used
- * @param ovpn_pid the PID of the openvpn pr= ocess
+ * @param nrp= t_key the registry key to set the rules under
+ * @param addresses name server= addresses
+ * @param= domains optional list of split routing domains
+ * @param search_domains optiona= l list of search domains
+ * @param dnssec boolean whether DNSSEC is to be used

+ * @param ovpn_pid = the PID of the openvpn process
*
*= @return NO_ERROR on success, or a Windows error code
*/<= /span>
static DWORD
-SetNrptRules(HKEY nrpt_key, const nrpt_address_t *addresses,=
- const char *dom= ains, BOOL dnssec, DWORD ovpn_pid)
+SetNrptRules(HKEY nrpt_key, const nrpt_address_t *addresses,= const char *domains,
+ const char *search_domains, BOOL dnssec, DWORD ovpn_pid)
{
DWORD err =3D NO_ERROR;
PWSTR wide_domains =3D L".\0"; /* DNS route everything by = default */

@@ -2573,7 +2598,14 @@
}
else
{
- SetNrptExcludeRules(nrpt_key, ovpn_pid);
+ PWSTR wide_se= arch_domains;
+ = wide_search_domains =3D utf8to16(search_domains);
+ if (!wide_search_domains)<= br>+ {
+ return ERROR_OUTOFMEMORY;=
+ }+ SetNrptExcludeRules(n= rpt_key, ovpn_pid, wide_search_domains);
+ free(wide_search_domains);
= }

/* Create address string list */=
@@ -2833,7 +2865,7 @@

= /* Set NRPT rules */
BOOL dnssec =3D (msg->flags= & nrpt_dnssec) !=3D 0;
- err =3D SetNrptRules(key, msg->addresses, msg->resolve_doma= ins, dnssec, ovpn_pid);
+ err =3D SetNrptRules(key, msg->addresses, msg->resolve_domain= s, msg->search_domains, dnssec, ovpn_pid);
if (err)=
{
goto out;
=

To view, visit change 905. To unsubscribe, or for help writi= ng mail filters, visit setti= ngs.

Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I4919af2b845a47787c08f454b10= 8ef376ea5c0f6
Gerrit-Change-Number: 905
Gerrit-PatchSet: 1
Gerrit-Owner: d12fk <heiko@...515...>
Gerrit-Reviewer: flichtenheld <frank@...2716...= 1...>
Gerrit-Reviewer: plaisthos <arne-openvpn@...1186...= .1227...>
Gerrit-CC: openvpn-devel <openvpn-devel@...1484...= ts.sourceforge.net>
Gerrit-Attention: plaisthos <arne-openvpn@...220...= ..1227...>
Gerrit-Attention: flichtenheld <frank@...2375...= 41...>
Gerrit-MessageType: newchange
--tgoUKK0UmC0=--