diff --git a/Patches/LineageOS-18.1/android_bionic/0003-hosts_toggle.patch b/Patches/LineageOS-18.1/android_bionic/0003-hosts_toggle.patch index b0025e4e..8f808ac5 100644 --- a/Patches/LineageOS-18.1/android_bionic/0003-hosts_toggle.patch +++ b/Patches/LineageOS-18.1/android_bionic/0003-hosts_toggle.patch @@ -1,4 +1,4 @@ -From e336a0c51b42f5a43d4d7216cf0de7fb27c8b138 Mon Sep 17 00:00:00 2001 +From f5cc53d8d4dfcffe5d1c7b029078803112e79919 Mon Sep 17 00:00:00 2001 From: Tad Date: Wed, 20 Apr 2022 00:40:52 -0400 Subject: [PATCH] Add a toggle to disable /etc/hosts lookup @@ -6,11 +6,11 @@ Subject: [PATCH] Add a toggle to disable /etc/hosts lookup Signed-off-by: Tad Change-Id: I92679c57e73228dc194e61a86ea1a18b2ac90e04 --- - libc/dns/net/getaddrinfo.c | 37 +++++++++++++++++++++++-------------- - 1 file changed, 23 insertions(+), 14 deletions(-) + libc/dns/net/getaddrinfo.c | 6 ++++++ + 1 file changed, 6 insertions(+) diff --git a/libc/dns/net/getaddrinfo.c b/libc/dns/net/getaddrinfo.c -index cc94b21e2..d4d1db259 100644 +index cc94b21e2..36c887a38 100644 --- a/libc/dns/net/getaddrinfo.c +++ b/libc/dns/net/getaddrinfo.c @@ -83,6 +83,7 @@ @@ -21,52 +21,18 @@ index cc94b21e2..d4d1db259 100644 #include #include #include -@@ -2129,23 +2130,31 @@ _files_getaddrinfo(void *rv, void *cb_data, va_list ap) - - memset(&sentinel, 0, sizeof(sentinel)); - cur = &sentinel; -- int gai_error = hc_getaddrinfo(name, NULL, pai, &cur); -- if (gai_error != EAI_SYSTEM) { -- *((struct addrinfo **)rv) = sentinel.ai_next; -- return (gai_error == 0 ? NS_SUCCESS : NS_NOTFOUND); -- } - --// fprintf(stderr, "_files_getaddrinfo() name = '%s'\n", name); -- memset(&sentinel, 0, sizeof(sentinel)); -- cur = &sentinel; -+ int hostsDisabled = 0; +@@ -2118,6 +2119,11 @@ found: + static int + _files_getaddrinfo(void *rv, void *cb_data, va_list ap) + { + char value[PROP_VALUE_MAX] = { 0 }; + if (__system_property_get("persist.security.hosts_disable", value) != 0) -+ hostsDisabled = atoi(value); - -- _sethtent(&hostf); -- while ((p = _gethtent(&hostf, name, pai)) != NULL) { -- cur->ai_next = p; -- while (cur && cur->ai_next) -- cur = cur->ai_next; -+ if (hostsDisabled == 0) { -+ int gai_error = hc_getaddrinfo(name, NULL, pai, &cur); -+ if (gai_error != EAI_SYSTEM) { -+ *((struct addrinfo **)rv) = sentinel.ai_next; -+ return (gai_error == 0 ? NS_SUCCESS : NS_NOTFOUND); -+ } ++ if (atoi(value) != 0) ++ return NS_NOTFOUND; + -+// fprintf(stderr, "_files_getaddrinfo() name = '%s'\n", name); -+ memset(&sentinel, 0, sizeof(sentinel)); -+ cur = &sentinel; -+ -+ _sethtent(&hostf); -+ while ((p = _gethtent(&hostf, name, pai)) != NULL) { -+ cur->ai_next = p; -+ while (cur && cur->ai_next) -+ cur = cur->ai_next; -+ } -+ _endhtent(&hostf); - } -- _endhtent(&hostf); - - *((struct addrinfo **)rv) = sentinel.ai_next; - if (sentinel.ai_next == NULL) + const char *name; + const struct addrinfo *pai; + struct addrinfo sentinel, *cur; -- 2.36.0 diff --git a/Patches/LineageOS-18.1/android_packages_modules_DnsResolver/0001-hosts_toggle.patch b/Patches/LineageOS-18.1/android_packages_modules_DnsResolver/0001-hosts_toggle.patch index fbc00e8d..9091fc30 100644 --- a/Patches/LineageOS-18.1/android_packages_modules_DnsResolver/0001-hosts_toggle.patch +++ b/Patches/LineageOS-18.1/android_packages_modules_DnsResolver/0001-hosts_toggle.patch @@ -1,4 +1,4 @@ -From 2cc44127b3140a9f86787022c5c3b78e0134c5d6 Mon Sep 17 00:00:00 2001 +From 738d94379dccd89de898b2de0d4ad97a57d8c8f8 Mon Sep 17 00:00:00 2001 From: Tad Date: Wed, 20 Apr 2022 00:40:53 -0400 Subject: [PATCH] Add a toggle to disable /etc/hosts lookup @@ -6,11 +6,11 @@ Subject: [PATCH] Add a toggle to disable /etc/hosts lookup Signed-off-by: Tad Change-Id: Iea165003474e1107dc77980985bf9928c369dbb5 --- - getaddrinfo.cpp | 24 +++++++++++++----------- - 1 file changed, 13 insertions(+), 11 deletions(-) + getaddrinfo.cpp | 4 ++++ + 1 file changed, 4 insertions(+) diff --git a/getaddrinfo.cpp b/getaddrinfo.cpp -index 071f6ac..da7333c 100644 +index 071f6ac..14891fc 100644 --- a/getaddrinfo.cpp +++ b/getaddrinfo.cpp @@ -57,6 +57,7 @@ @@ -21,38 +21,16 @@ index 071f6ac..da7333c 100644 #include "Experiments.h" #include "netd_resolv/resolv.h" -@@ -1561,19 +1562,20 @@ static bool files_getaddrinfo(const size_t netid, const char* name, const addrin +@@ -1556,6 +1557,9 @@ static struct addrinfo* getCustomHosts(const size_t netid, const char* _Nonnull + + static bool files_getaddrinfo(const size_t netid, const char* name, const addrinfo* pai, + addrinfo** res) { ++ if (android::base::GetIntProperty("persist.security.hosts_disable", 0) != 0) ++ return false; ++ + struct addrinfo sentinel = {}; + struct addrinfo *p, *cur; FILE* hostf = nullptr; - - cur = &sentinel; -+ if (android::base::GetIntProperty("persist.security.hosts_disable", 0) == 0) { -+ int hc_error = hc_getaddrinfo(name, pai, &cur); -+ if (hc_error != EAI_SYSTEM) { -+ *res = sentinel.ai_next; -+ return sentinel.ai_next != NULL; -+ } - -- int hc_error = hc_getaddrinfo(name, pai, &cur); -- if (hc_error != EAI_SYSTEM) { -- *res = sentinel.ai_next; -- return sentinel.ai_next != NULL; -- } -- -- _sethtent(&hostf); -- while ((p = _gethtent(&hostf, name, pai)) != nullptr) { -- cur->ai_next = p; -- while (cur && cur->ai_next) cur = cur->ai_next; -+ _sethtent(&hostf); -+ while ((p = _gethtent(&hostf, name, pai)) != nullptr) { -+ cur->ai_next = p; -+ while (cur && cur->ai_next) cur = cur->ai_next; -+ } -+ _endhtent(&hostf); - } -- _endhtent(&hostf); - - if ((p = getCustomHosts(netid, name, pai)) != nullptr) { - cur->ai_next = p; -- 2.36.0