Allow dns hook to fail a resolve and add domains

This lets people with crap ISPs that resolve domains
that they shouldn't to use the game without
changing their DNS server
This commit is contained in:
Will Toohey 2019-11-17 15:08:25 +10:00
parent 9f933bb371
commit 4bc7eee909
3 changed files with 46 additions and 5 deletions

View File

@ -156,7 +156,6 @@ HRESULT dns_hook_push(const wchar_t *from_src, const wchar_t *to_src)
wchar_t *to; wchar_t *to;
assert(from_src != NULL); assert(from_src != NULL);
assert(to_src != NULL);
to = NULL; to = NULL;
from = NULL; from = NULL;
@ -172,12 +171,14 @@ HRESULT dns_hook_push(const wchar_t *from_src, const wchar_t *to_src)
goto end; goto end;
} }
to = _wcsdup(to_src); if(to_src != NULL) {
to = _wcsdup(to_src);
if (to == NULL) { if (to == NULL) {
hr = E_OUTOFMEMORY; hr = E_OUTOFMEMORY;
goto end; goto end;
}
} }
newmem = realloc( newmem = realloc(
@ -250,6 +251,13 @@ static DNS_STATUS WINAPI hook_DnsQuery_A(
pos = &dns_hook_entries[i]; pos = &dns_hook_entries[i];
if (_wcsicmp(wstr, pos->from) == 0) { if (_wcsicmp(wstr, pos->from) == 0) {
if(pos->to == NULL) {
LeaveCriticalSection(&dns_hook_lock);
hr = HRESULT_FROM_WIN32(DNS_ERROR_RCODE_NAME_ERROR);
goto end;
}
wcstombs_s(&str_c, NULL, 0, pos->to, 0); wcstombs_s(&str_c, NULL, 0, pos->to, 0);
str = malloc(str_c * sizeof(char)); str = malloc(str_c * sizeof(char));
@ -307,6 +315,11 @@ static DNS_STATUS WINAPI hook_DnsQuery_W(
pos = &dns_hook_entries[i]; pos = &dns_hook_entries[i];
if (_wcsicmp(pszName, pos->from) == 0) { if (_wcsicmp(pszName, pos->from) == 0) {
if(pos->to == NULL) {
LeaveCriticalSection(&dns_hook_lock);
return HRESULT_FROM_WIN32(DNS_ERROR_RCODE_NAME_ERROR);
}
pszName = pos->to; pszName = pos->to;
break; break;
@ -346,6 +359,11 @@ static DNS_STATUS WINAPI hook_DnsQueryEx(
pos = &dns_hook_entries[i]; pos = &dns_hook_entries[i];
if (_wcsicmp(pRequest->QueryName, pos->from) == 0) { if (_wcsicmp(pRequest->QueryName, pos->from) == 0) {
if(pos->to == NULL) {
LeaveCriticalSection(&dns_hook_lock);
return HRESULT_FROM_WIN32(DNS_ERROR_RCODE_NAME_ERROR);
}
pRequest->QueryName = pos->to; pRequest->QueryName = pos->to;
break; break;
@ -408,6 +426,13 @@ static int WSAAPI hook_getaddrinfo(
pos = &dns_hook_entries[i]; pos = &dns_hook_entries[i];
if (_wcsicmp(wstr, pos->from) == 0) { if (_wcsicmp(wstr, pos->from) == 0) {
if(pos->to == NULL) {
LeaveCriticalSection(&dns_hook_lock);
result = EAI_NONAME;
goto end;
}
wcstombs_s(&str_c, NULL, 0, pos->to, 0); wcstombs_s(&str_c, NULL, 0, pos->to, 0);
str = malloc(str_c * sizeof(char)); str = malloc(str_c * sizeof(char));

View File

@ -4,5 +4,6 @@
#include <stddef.h> #include <stddef.h>
// if to_src is NULL, all lookups for from_src will fail
HRESULT dns_hook_push(const wchar_t *from_src, const wchar_t *to_src); HRESULT dns_hook_push(const wchar_t *from_src, const wchar_t *to_src);

View File

@ -64,5 +64,20 @@ HRESULT dns_platform_hook_init(const struct dns_config *cfg)
return hr; return hr;
} }
// if your ISP resolves bad domains, it will kill the network. These 2
// *cannot* resolve
hr = dns_hook_push(L"mobirouter.loc", NULL);
if (FAILED(hr)) {
return hr;
}
hr = dns_hook_push(L"dslrouter.loc", NULL);
if (FAILED(hr)) {
return hr;
}
return S_OK; return S_OK;
} }