Enable Windows dnscache again

This commit is contained in:
Daniel
2021-03-20 23:14:38 +01:00
parent 01e7160bfe
commit bc341b60c0

View File

@@ -33,7 +33,7 @@ func start(ch chan packet.Packet) error {
} }
go windowskext.Handler(ch) go windowskext.Handler(ch)
go handleWindowsDNSCache() go checkWindowsDNSCache()
return nil return nil
} }
@@ -43,37 +43,21 @@ func stop() error {
return windowskext.Stop() return windowskext.Stop()
} }
func handleWindowsDNSCache() { func checkWindowsDNSCache() {
status, err := osdetail.GetServiceStatus("dnscache")
err := osdetail.StopService("dnscache")
if err != nil { if err != nil {
// cannot stop dnscache, try disabling log.Warningf("firewall/interception: failed to check status of Windows DNS-Client: %s", err)
if err == osdetail.ErrServiceNotStoppable {
err := osdetail.DisableDNSCache()
if err != nil {
log.Warningf("firewall/interception: failed to disable Windows Service \"DNS Client\" (dnscache) for better interception: %s", err)
notifyDisableDNSCache()
}
notifyRebootRequired()
return
}
// error while stopping service
log.Warningf("firewall/interception: failed to stop Windows Service \"DNS Client\" (dnscache) for better interception: %s", err)
notifyDisableDNSCache()
} }
// log that service is stopped if status == osdetail.StatusStopped {
log.Info("firewall/interception: Windows Service \"DNS Client\" (dnscache) is stopped for better interception") err := osdetail.EnableDNSCache()
if err != nil {
} log.Warningf("firewall/interception: failed to enable Windows Service \"DNS Client\" (dnscache): %s", err)
} else {
func notifyDisableDNSCache() { log.Warningf("firewall/interception: successfully enabled the dnscache")
(&notifications.Notification{ notifyRebootRequired()
EventID: "interception:windows-disable-dns-cache", }
Message: "The Portmaster needs the Windows Service \"DNS Client\" (dnscache) to be disabled for best effectiveness.", }
Type: notifications.Warning,
}).Save()
} }
func notifyRebootRequired() { func notifyRebootRequired() {