From: "d12fk (Code Review)" Date: Thu, 3 Jul 2025 03:56:30 +0000 References: Reply-To: heiko@...515..., arne-openvpn@...1227..., openvpn-devel@lists.sourceforge.net, frank@...2641... Message-ID: <4b5eb17d0f9acf689e61bd07ba9b49979fd6c7c1-HTML@...2715...> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Disposition: inline Content-Type: multipart/alternative; boundary="uDSfDAYvmvI="; charset=UTF-8 Subject: [Openvpn-devel] [S] Change in openvpn[master]: mac dns: compare servers before restoring backup List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: plaisthos , flichtenheld Cc: openvpn-devel --uDSfDAYvmvI= 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/+/1075?usp=3Demail to review the following change. Change subject: mac dns: compare servers before restoring backup ...................................................................... mac dns: compare servers before restoring backup In case anything changed the global DNS server addresses, while the tunnel was connected, do not restore the backup of the global DNS configuration we made when connecting. Doing so would likely change DNS to something unexpected. Instead just clear the backup and leave a message in the log. Change-Id: I1aabd62e60dd18408a57baccbb0f4ebd6d2f8d67 Signed-off-by: Heiko Hund --- M distro/dns-scripts/macos-dns-updown.sh 1 file changed, 14 insertions(+), 4 deletions(-) git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/75/1075/1 diff --git a/distro/dns-scripts/macos-dns-updown.sh b/distro/dns-scripts/ma= cos-dns-updown.sh index 56f1009..282b034 100644 --- a/distro/dns-scripts/macos-dns-updown.sh +++ b/distro/dns-scripts/macos-dns-updown.sh @@ -111,6 +111,10 @@ property_value State:/Network/Global/DNS SearchDomains } +function get_server_addresses { + property_value State:/Network/Global/DNS ServerAddresses +} + function set_search_domains { [ -n "$1" ] || return local dns_key=3D$(primary_dns_key) @@ -239,11 +243,10 @@ function unset_dns { local n=3D"$(find_compat_profile)" - local addresses=3D"$(addresses_string $n)" - local search_domains=3D"$(search_domains_string $n)" local match_domains=3D"$(match_domains_string $n)" if [ -n "$match_domains" ]; then + local search_domains=3D"$(search_domains_string $n)" echo "remove ${itf_dns_key}" | /usr/sbin/scutil unset_search_domains "$search_domains" else @@ -252,8 +255,15 @@ [[ "${dns_backup_key}" =3D~ ${dev}/ ]] || return local cmds=3D"" - cmds+=3D"get ${dns_backup_key}\n" - cmds+=3D"set $(primary_dns_key)\n" + local servers=3D"$(get_server_addresses)" + local addresses=3D"$(addresses_string $n)" + # Only restore backup if the server addresses match + if [ "${servers}" =3D "${addresses}" ]; then + cmds+=3D"get ${dns_backup_key}\n" + cmds+=3D"set $(primary_dns_key)\n" + else + echo "not restoring global DNS configuration, server addresses= have changed" + fi cmds+=3D"remove ${dns_backup_key}\n" echo -e "${cmds}" | /usr/sbin/scutil fi -- To view, visit http://gerrit.openvpn.net/c/openvpn/+/1075?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: I1aabd62e60dd18408a57baccbb0f4ebd6d2f8d67 Gerrit-Change-Number: 1075 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 --uDSfDAYvmvI= 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.

V= iew Change

mac dns: compare servers before restoring backup

In c= ase anything changed the global DNS server addresses, while the
tunnel w= as connected, do not restore the backup of the global DNS
configuration = we made when connecting. Doing so would likely change
DNS to something u= nexpected. Instead just clear the backup and leave
a message in the log.=

Change-Id: I1aabd62e60dd18408a57baccbb0f4ebd6d2f8d67
Signed-off-= by: Heiko Hund <heiko@...2662...>
---
M distro/dns-scripts/maco= s-dns-updown.sh
1 file changed, 14 insertions(+), 4 deletions(-)

=
git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/75/1075/1
diff --git a/distro/dns-scripts/macos-dns-updown.sh b/distro/dns-scr=
ipts/macos-dns-updown.sh
index 56f1009..282b034 100644
--- a/distro/dns-scripts/macos-dns-updown.sh
++= + b/distro/dns-scripts/macos-dns-updown.sh
@@ -111,6 +111,1= 0 @@
property_value State:/Network/Global/DNS SearchDo= mains
}

+function get_server_addresses {
+ property_value State:/Network/Global= /DNS ServerAddresses
= +}
+
= function set_search_domains {
[ -n "$1" ] |= | return
local dns_key=3D$(primary_dns_key)
= @@ -239,11 +243,10 @@

function uns= et_dns {
local n=3D"$(find_compat_profile)"<= /span>
- local addresses=3D= "$(addresses_string $n)"
- local search_domains=3D"$(search_domains_string $n)&q= uot;
local match_domains=3D"$(match_domains_strin= g $n)"

if [ -n "$match_dom= ains" ]; then
+ = local search_domains=3D"$(search_domains_string $n)"
echo "remove ${itf_dns_key}" | /usr/sbin/scut= il
unset_search_domains "$search_domains"= ;
else
@@ -252,8 +255,15 @@
= [[ "${dns_backup_key}" =3D~ ${dev}/ ]] || return

local cmds=3D""<= br>- cmds+=3D"get ${d= ns_backup_key}\n"
= - cmds+=3D"set $(primary_dns_key)\n"
+ local servers=3D"$(get_serve= r_addresses)"
+ = local addresses=3D"$(addresses_string $n)"
+ # Only restore backup if th= e server addresses match

+ if [ "${servers}" =3D "${addresses}" ]; th= en
+ cmds+= =3D"get ${dns_backup_key}\n"
+ cmds+=3D"set $(primary_dns_key)\n"=
+ else=
+ echo "not= restoring global DNS configuration, server addresses have changed"
+ fi
<= span> cmds+=3D"remove ${dns_backup_key}\n"

echo -e "${cmds}" | /usr/sbin/scutil

= fi

To view, visit change 1075. To unsub= scribe, or for help writing mail filters, visit settings.

Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I1aabd62e60dd18408a57baccbb0= f4ebd6d2f8d67
Gerrit-Change-Number: 1075
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
--uDSfDAYvmvI=--