From: "flichtenheld (Code Review)"
Date: Thu, 8 Jan 2026 13:36:56 +0000
In-Reply-To:
References:
Reply-To: frank@...2641..., arne-openvpn@...1227...,
openvpn-devel@lists.sourceforge.net
Message-ID: <99612b2afb69a01f68badb8f279b3c7ab7afca1f-EmailReplacePatchSet-HTML@...2715...>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
Content-Disposition: inline
Content-Type: multipart/alternative; boundary="4Swf2QWic+Q="; charset=UTF-8
Subject: [Openvpn-devel] [M] Change in openvpn[master]: openvpnserv: Factor
out the string conversion from GetItfDnsDomains
List-Id:
List-Unsubscribe: ,
List-Archive:
List-Post:
List-Help:
List-Subscribe: ,
To: plaisthos
Cc: openvpn-devel
--4Swf2QWic+Q=
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
Attention is currently required from: plaisthos.
Hello plaisthos,
I'd like you to reexamine a change. Please visit
http://gerrit.openvpn.net/c/openvpn/+/1458?usp=3Demail
to look at the new patch set (#4).
Change subject: openvpnserv: Factor out the string conversion from GetItfDn=
sDomains
......................................................................
openvpnserv: Factor out the string conversion from GetItfDnsDomains
Mostly so that we can actually test it. Since that
code does some in-place conversions a test would be
good.
Change-Id: Ib517457015b754d59aeb70827c4795aa6154728c
Signed-off-by: Frank Lichtenheld
---
M src/openvpnserv/interactive.c
1 file changed, 101 insertions(+), 72 deletions(-)
git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/58/1458/4
diff --git a/src/openvpnserv/interactive.c b/src/openvpnserv/interactive.c
index 8b817ed..00657b0 100644
--- a/src/openvpnserv/interactive.c
+++ b/src/openvpnserv/interactive.c
@@ -2143,6 +2143,106 @@
}
/**
+ * Convert interface specific domain suffix(es) from comma-separated
+ * string to MULTI_SZ string.
+ *
+ * The \p domains paramter will be set to a MULTI_SZ domains string.
+ * In case of an error \p size is set to 0 and the contents of \p domains
+ * are invalid.
+ * Note that domains are deleted from the string if they match a search do=
main.
+ *
+ * @param[in] search_domains optional list of search domains
+ * @param[in,out] domains buffer that contains the input comma-sep=
arated
+ * string and will contain the MULTI_SZ out=
put string
+ * @param[in,out] size pointer to size of the input string in b=
ytes. Will be
+ * set to the size of the string returned, =
including
+ * the terminating zeros or 0.
+ * @param[in] buf_size size of the \p domains buffer
+ *
+ * @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,
+ * ERROR_MORE_DATA if the list did not fit into the buffer
+ */
+static LSTATUS
+ConvertItfDnsDomains(PCWSTR search_domains, PWSTR domains, PDWORD size, co=
nst DWORD buf_size)
+{
+ const DWORD glyph_size =3D sizeof(*domains);
+ const DWORD buf_len =3D buf_size / glyph_size;
+
+ /*
+ * Found domain(s), now convert them:
+ * - prefix each domain with a dot
+ * - convert comma separated list to MULTI_SZ
+ */
+ PWCHAR pos =3D domains;
+ while (TRUE)
+ {
+ /* Terminate the domain at the next comma */
+ PWCHAR comma =3D wcschr(pos, ',');
+ if (comma)
+ {
+ *comma =3D '\0';
+ }
+
+ DWORD domain_len =3D (DWORD)wcslen(pos);
+ DWORD domain_size =3D domain_len * glyph_size;
+ DWORD converted_size =3D (DWORD)(pos - domains) * glyph_size;
+
+ /* Ignore itf domains which match a pushed search domain */
+ if (ListContainsDomain(search_domains, pos, domain_len))
+ {
+ if (comma)
+ {
+ /* Overwrite the ignored domain with remaining one(s) */
+ memmove(pos, comma + 1, buf_size - converted_size);
+ *size -=3D domain_size + glyph_size;
+ continue;
+ }
+ else
+ {
+ /* This was the last domain */
+ *pos =3D '\0';
+ *size -=3D domain_size;
+ return wcslen(domains) ? NO_ERROR : ERROR_FILE_NOT_FOUND;
+ }
+ }
+
+ /* Add space for the leading dot */
+ domain_len +=3D 1;
+ domain_size +=3D glyph_size;
+
+ /* Space for the terminating zeros */
+ const DWORD extra_size =3D 2 * glyph_size;
+
+ /* Check for enough space to convert this domain */
+ if (converted_size + domain_size + extra_size > buf_size)
+ {
+ /* Domain doesn't fit, bad luck if it's the first one */
+ *pos =3D '\0';
+ *size =3D converted_size =3D=3D 0 ? 0 : converted_size + glyph=
_size;
+ return ERROR_MORE_DATA;
+ }
+
+ /* Prefix domain at pos with the dot */
+ memmove(pos + 1, pos, buf_size - converted_size - glyph_size);
+ domains[buf_len - 1] =3D '\0';
+ *pos =3D '.';
+ *size +=3D glyph_size;
+
+ if (!comma)
+ {
+ /* Conversion is done */
+ *(pos + domain_len) =3D '\0';
+ *size +=3D glyph_size;
+ return NO_ERROR;
+ }
+
+ /* Comma pos is now +1 after adding leading dot */
+ pos =3D comma + 2;
+ }
+}
+
+/**
* Return interface specific domain suffix(es)
*
* The \p domains paramter will be set to a MULTI_SZ domains string.
@@ -2174,7 +2274,6 @@
LSTATUS err =3D ERROR_FILE_NOT_FOUND;
const DWORD buf_size =3D *size;
const DWORD glyph_size =3D sizeof(*domains);
- const DWORD buf_len =3D buf_size / glyph_size;
PWSTR values[] =3D { L"SearchList", L"Domain", L"DhcpDomainSearchList"=
, L"DhcpDomain", NULL };
for (int i =3D 0; values[i]; i++)
@@ -2183,77 +2282,7 @@
err =3D RegGetValueW(itf, NULL, values[i], RRF_RT_REG_SZ, NULL, (P=
BYTE)domains, size);
if (!err && *size > glyph_size && domains[(*size / glyph_size) - 1=
] =3D=3D '\0' && wcschr(domains, '.'))
{
- /*
- * Found domain(s), now convert them:
- * - prefix each domain with a dot
- * - convert comma separated list to MULTI_SZ
- */
- PWCHAR pos =3D domains;
- while (TRUE)
- {
- /* Terminate the domain at the next comma */
- PWCHAR comma =3D wcschr(pos, ',');
- if (comma)
- {
- *comma =3D '\0';
- }
-
- DWORD domain_len =3D (DWORD)wcslen(pos);
- DWORD domain_size =3D domain_len * glyph_size;
- DWORD converted_size =3D (DWORD)(pos - domains) * glyph_si=
ze;
-
- /* Ignore itf domains which match a pushed search domain */
- if (ListContainsDomain(search_domains, pos, domain_len))
- {
- if (comma)
- {
- /* Overwrite the ignored domain with remaining one=
(s) */
- memmove(pos, comma + 1, buf_size - converted_size);
- *size -=3D domain_size + glyph_size;
- continue;
- }
- else
- {
- /* This was the last domain */
- *pos =3D '\0';
- *size -=3D domain_size;
- return wcslen(domains) ? NO_ERROR : ERROR_FILE_NOT=
_FOUND;
- }
- }
-
- /* Add space for the leading dot */
- domain_len +=3D 1;
- domain_size +=3D glyph_size;
-
- /* Space for the terminating zeros */
- const DWORD extra_size =3D 2 * glyph_size;
-
- /* Check for enough space to convert this domain */
- if (converted_size + domain_size + extra_size > buf_size)
- {
- /* Domain doesn't fit, bad luck if it's the first one =
*/
- *pos =3D '\0';
- *size =3D converted_size =3D=3D 0 ? 0 : converted_size=
+ glyph_size;
- return ERROR_MORE_DATA;
- }
-
- /* Prefix domain at pos with the dot */
- memmove(pos + 1, pos, buf_size - converted_size - glyph_si=
ze);
- domains[buf_len - 1] =3D '\0';
- *pos =3D '.';
- *size +=3D glyph_size;
-
- if (!comma)
- {
- /* Conversion is done */
- *(pos + domain_len) =3D '\0';
- *size +=3D glyph_size;
- return NO_ERROR;
- }
-
- /* Comma pos is now +1 after adding leading dot */
- pos =3D comma + 2;
- }
+ return ConvertItfDnsDomains(search_domains, domains, size, buf=
_size);
}
}
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/1458?usp=3Demail
To unsubscribe, or for help writing mail filters, visit http://gerrit.openv=
pn.net/settings?usp=3Demail
Gerrit-MessageType: newpatchset
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: Ib517457015b754d59aeb70827c4795aa6154728c
Gerrit-Change-Number: 1458
Gerrit-PatchSet: 4
Gerrit-Owner: flichtenheld
Gerrit-Reviewer: plaisthos
Gerrit-CC: openvpn-devel
Gerrit-Attention: plaisthos
--4Swf2QWic+Q=
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
Attention is cur=
rently required from: plaisthos.
flichtenheld uploaded patch set #4 to this change.
<=
p>View C=
hange
openvpnserv: Factor out the string conversion fr=
om GetItfDnsDomains
Mostly so that we can actually test it. Since th=
at
code does some in-place conversions a test would be
good.
C=
hange-Id: Ib517457015b754d59aeb70827c4795aa6154728c
Signed-off-by: Frank=
Lichtenheld <frank@...2641...>
---
M src/openvpnserv/interacti=
ve.c
1 file changed, 101 insertions(+), 72 deletions(-)
git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/58/=
1458/4diff --git a/src/openvpnserv/interactive.c b/src/openvpnserv=
/interactive.c
index 8b817ed..00657b0 100644
--- a/src/openvpnserv/interactive.c
+++ b/src/openvpnserv=
/interactive.c
@@ -2143,6 +2143,106 @@
}=
span>
/**
+ * Convert interface specific domain suffix(es) from comm=
a-separated
+ * strin=
g to MULTI_SZ string.
+ *
+ * The \p domai=
ns paramter will be set to a MULTI_SZ domains string.
+ * In case of an error \p size is set to =
0 and the contents of \p domains
+ * are invalid.
+ * Note that domains are deleted from the string if they match a s=
earch domain.
+ *
+ * @param[in] searc=
h_domains optional list of search domains
+ * @param[in,out] domains buffer that contai=
ns the input comma-separated
+ * string and will contain the MULT=
I_SZ output string
+ =
* @param[in,out] size pointer to size of the input string in byt=
es. Will be
+ * =
set to the size of the string returned, including=
+ * =
the terminating zeros or 0.
+ * @param[in] buf_size size of the \p dom=
ains buffer
+ *
+ * @return LSTATUS NO_ERR=
OR if the domain suffix(es) were read successfully,
+ * ERROR_FILE_NOT_FOUND if no dom=
ain was found for the interface,
+ * ERROR_MORE_DATA if the list did not fit into the bu=
ffer
+ */
<=
span style=3D"color: hsl(120, 100%, 40%);">+static LSTATUS
+ConvertItfDnsDomains(PCWSTR search_d=
omains, PWSTR domains, PDWORD size, const DWORD buf_size)
+{
+ const DWORD glyph_size =3D sizeof(*domains);=
+ const DWORD buf_len =
=3D buf_size / glyph_size;
+
+ /*
+ * Found domain(s), n=
ow convert them:
+ =
* - prefix each domain with a dot
+ * - convert comma separated list to MULTI_SZ
+ */
+ PWCHAR pos =3D domains;
+ while (TRUE)
+ {
+ /* Terminate the domain at the next co=
mma */
+ PWCHA=
R comma =3D wcschr(pos, ',');
+ if (comma)
+ {
+ *comma =3D '\0';
+ }
+
+ =
DWORD domain_len =3D (DWORD)wcslen(pos);
+ DWORD domain_size =3D domain_len * glyph_si=
ze;
+ DWORD co=
nverted_size =3D (DWORD)(pos - domains) * glyph_size;
+
+ /* Ignore itf domains which match a pushed search do=
main */
+ if (=
ListContainsDomain(search_domains, pos, domain_len))
+ {
+ if (comma)
+ {
+ /* Overwrite the ignored domain with r=
emaining one(s) */
+ =
memmove(pos, comma + 1, buf_size - converted_size);+ *size -=3D d=
omain_size + glyph_size;
+ continue;
+ }
+ else
+ {
+ =
/* This was the last domain */
+ *pos =3D '\0';
+ *size -=3D domain=
_size;
+ =
return wcslen(domains) ? NO_ERROR : ERROR_FILE_NOT_FOUND;
+ }
+ }
+
+ /* Add space for the leading dot */
+ domain_len +=3D 1;
+ domain_size +=3D glyph_size;=
span>
+
+ /* Space for the terminating zer=
os */
+ const =
DWORD extra_size =3D 2 * glyph_size;
+
+ =
/* Check for enough space to convert this domain */
+ if (converted_size + domain_s=
ize + extra_size > buf_size)
+ {
+ /* Domain doesn't fit, bad luck if it's the first one=
*/
+ *pos=
=3D '\0';
+ =
*size =3D converted_size =3D=3D 0 ? 0 : converted_size + glyph_s=
ize;
+ ret=
urn ERROR_MORE_DATA;
=
+ }
++ /* Prefix domain at =
pos with the dot */
+=
memmove(pos + 1, pos, buf_size - converted_size - glyph_size);
+ domains[buf_len =
- 1] =3D '\0';
+ *pos =3D '.';
+ *size +=3D glyph_size;
+
+ if (!comma)
+ {
+ =
/* Conversion is done */
+ *(pos + domain_len) =3D '\0';
+ *size +=3D glyph_size=
;
+ return=
NO_ERROR;
+ }=
+
+ /* Comma pos is now +1 after a=
dding leading dot */
=
+ pos =3D comma + 2;
+ }
+}
+
+/**
* Return interface =
specific domain suffix(es)
*
* The \p d=
omains paramter will be set to a MULTI_SZ domains string.
@=
@ -2174,7 +2274,6 @@
LSTATUS err =3D ERROR_FILE_NOT_FO=
UND;
const DWORD buf_size =3D *size;
=
const DWORD glyph_size =3D sizeof(*domains);
- const DWORD buf_len =3D buf_size / glyph_siz=
e;
PWSTR values[] =3D { L"SearchList", L&quo=
t;Domain", L"DhcpDomainSearchList", L"DhcpDomain",=
NULL };
for (int i =3D 0; values[i]=
; i++)
@@ -2183,77 +2282,7 @@
err =
=3D RegGetValueW(itf, NULL, values[i], RRF_RT_REG_SZ, NULL, (PBYTE)domains,=
size);
if (!err && *size > glyph_size =
&& domains[(*size / glyph_size) - 1] =3D=3D '\0' &&=
wcschr(domains, '.'))
{
- /*
- * Found domain(s), now convert th=
em:
- * -=
prefix each domain with a dot
- * - convert comma separated list to MULTI_SZ=
- */
- PWCHAR pos =3D domains=
;
- while (T=
RUE)
- {
- /* Termin=
ate the domain at the next comma */
- PWCHAR comma =3D wcschr(pos, ',');
- if (comm=
a)
- {=
span>
- *co=
mma =3D '\0';
-=
}
-
- DWORD dom=
ain_len =3D (DWORD)wcslen(pos);
- DWORD domain_size =3D domain_len * glyph_size;
- DWORD co=
nverted_size =3D (DWORD)(pos - domains) * glyph_size;
-
- /* Ignore itf domains which match a pushed searc=
h domain */
- =
if (ListContainsDomain(search_domains, pos, domain_len))
- {
- if (comma)<=
br>- {<=
br>- /* Ov=
erwrite the ignored domain with remaining one(s) */
- memmove(pos, comma =
+ 1, buf_size - converted_size);
- *size -=3D domain_size + glyph_size;
- c=
ontinue;
- =
}
- =
else
- =
{
- =
/* This was the last domain */
- *pos =3D '\0';
- *si=
ze -=3D domain_size;
- =
return wcslen(domains) ? NO_ERROR : ERROR_FILE_NOT_F=
OUND;
- =
}
- =
}
-
- /* Add space for the lead=
ing dot */
- =
domain_len +=3D 1;
- domain_size +=3D glyph_size;
-
- /* Space for the terminating zeros */
- const DWORD extra_size =
=3D 2 * glyph_size;
-=
span>
- /* Chec=
k for enough space to convert this domain */
- if (converted_size + domain_size + e=
xtra_size > buf_size)
- {
- =
/* Domain doesn't fit, bad luck if it's the firs=
t one */
- =
*pos =3D '\0';
- *size =3D converted_size =3D=3D 0 ? 0 : convert=
ed_size + glyph_size;
-=
return ERROR_MORE_DATA;
- }
-
- =
/* Prefix domain at pos with the dot */
- memmove(pos + 1, pos, buf_s=
ize - converted_size - glyph_size);
- domains[buf_len - 1] =3D '\0';=
- *pos =3D =
9;.';
- =
*size +=3D glyph_size;
-
- =
if (!comma)
- =
{
- =
/* Conversion is done */
- *(pos + domain_len) =3D '\0';- *size +=3D=
glyph_size;
- =
return NO_ERROR;
- }
-
- /* =
Comma pos is now +1 after adding leading dot */
- pos =3D comma + 2;
- }
+ return ConvertItfDnsDomains(s=
earch_domains, domains, size, buf_size);
}<=
br> }
To vi=
ew, visit change 1458. To unsubscribe, or for help writing mail filters, visit =
settings.
Gerrit-MessageType: newpatchset
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: Ib517457015b754d59aeb70827c4=
795aa6154728c
Gerrit-Change-Number: 1458
Gerrit-PatchSet: 4
Gerrit-Owner: flichtenheld <frank@...2723...=
.>
Gerrit-Reviewer: plaisthos <arne-openvpn@...1186...=
.1227...>
Gerrit-CC: openvpn-devel <openvpn-devel@...1484...=
ts.sourceforge.net>
Gerrit-Attention: plaisthos <arne-openvpn@...220...=
..1227...>
=
--4Swf2QWic+Q=--