From b3f50d42603367edc3f7cb1023fb3eca4dfae80f Mon Sep 17 00:00:00 2001 From: Justin Reichardt Date: Tue, 1 Mar 2022 12:36:30 -0600 Subject: [PATCH] Whitelisted entries are removed from hosts file --- src/rhosts.go | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/src/rhosts.go b/src/rhosts.go index e276960..05d11af 100644 --- a/src/rhosts.go +++ b/src/rhosts.go @@ -83,7 +83,7 @@ func main() { log.Print("Failed to failed to copy rhosts static entries") continue } - removeduplicates(&siteBuff) + removeduplicates(&siteBuff, &whitelist) err = write2tmp(tmpdir, &siteBuff) if (err != nil){ log.Print("Failed to write sites to tmpfile") @@ -382,8 +382,8 @@ func writesites(sites []string, tmpdir string, siteBuff *[]siteList) (err error) *siteBuff = append(*siteBuff,localList) return } -// removeduplicates removes any duplicate addresses -func removeduplicates(siteBuff *[]siteList){ +// removeduplicates removes any duplicate or uneeded/unwanted addresses +func removeduplicates(siteBuff *[]siteList, whitelist *[]string){ var safewords = []string{"localhost", "localhost.localdomain", "broadcasthost", "ip6-loopback", "ip6-localhost", "ip6-localnet", "ip6-mcastprefix", "ip6-allnodes", "ip6-allrouters", "ip6-allhosts", "local"} var counter = uint(0) log.Print("Checking for duplicates") @@ -415,6 +415,16 @@ func removeduplicates(siteBuff *[]siteList){ if *(entry[i].r) == true { continue } + for _,w := range(*whitelist){ + if *e.s == w { + *(entry[i].r) = true + counter ++ + break + } + } + if *(entry[i].r) == true { + continue + } if i == lenEntry { break }