DivestOS/Patches/LineageOS-18.1/android_packages_modules_DnsResolver/0001-hosts_toggle.patch
Tad 9a6c7a2684 18.1: Add toggle for /etc/hosts
TODO: 19.1 and maybe 17.1

Tested working on klte/18.1

Signed-off-by: Tad <tad@spotco.us>
2022-04-20 16:40:22 -04:00

59 lines
1.8 KiB
Diff

From 2cc44127b3140a9f86787022c5c3b78e0134c5d6 Mon Sep 17 00:00:00 2001
From: Tad <tad@spotco.us>
Date: Wed, 20 Apr 2022 00:40:53 -0400
Subject: [PATCH] Add a toggle to disable /etc/hosts lookup
Signed-off-by: Tad <tad@spotco.us>
Change-Id: Iea165003474e1107dc77980985bf9928c369dbb5
---
getaddrinfo.cpp | 24 +++++++++++++-----------
1 file changed, 13 insertions(+), 11 deletions(-)
diff --git a/getaddrinfo.cpp b/getaddrinfo.cpp
index 071f6ac..da7333c 100644
--- a/getaddrinfo.cpp
+++ b/getaddrinfo.cpp
@@ -57,6 +57,7 @@
#include <future>
#include <android-base/logging.h>
+#include <android-base/properties.h>
#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
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