diff --git a/base/services/dnsrslvr/cache.c b/base/services/dnsrslvr/cache.c index af4cc2a8597..e61cc8695a7 100644 --- a/base/services/dnsrslvr/cache.c +++ b/base/services/dnsrslvr/cache.c @@ -44,7 +44,7 @@ DnsIntCacheFree(VOID) if (!DnsCache.RecordList.Flink) return; - DnsIntCacheFlush(); + DnsIntCacheFlush(CACHE_FLUSH_ALL); DeleteCriticalSection(&DnsCache.Lock); DnsCacheInitialized = FALSE; @@ -65,13 +65,14 @@ DnsIntCacheRemoveEntryItem(PRESOLVER_CACHE_ENTRY CacheEntry) HeapFree(GetProcessHeap(), 0, CacheEntry); } -VOID -DnsIntCacheFlush(VOID) +DNS_STATUS +DnsIntCacheFlush( + _In_ ULONG ulFlags) { - PLIST_ENTRY Entry; + PLIST_ENTRY Entry, NextEntry; PRESOLVER_CACHE_ENTRY CacheEntry; - DPRINT("DnsIntCacheFlush()\n"); + DPRINT("DnsIntCacheFlush(%lu)\n", ulFlags); /* Lock the cache */ DnsCacheLock(); @@ -80,18 +81,24 @@ DnsIntCacheFlush(VOID) Entry = DnsCache.RecordList.Flink; while (Entry != &DnsCache.RecordList) { + NextEntry = Entry->Flink; + /* Get this entry */ CacheEntry = CONTAINING_RECORD(Entry, RESOLVER_CACHE_ENTRY, CacheLink); /* Remove it from list */ - DnsIntCacheRemoveEntryItem(CacheEntry); + if (((ulFlags & CACHE_FLUSH_HOSTS_FILE_ENTRIES) && (CacheEntry->bHostsFileEntry != FALSE)) || + ((ulFlags & CACHE_FLUSH_NON_HOSTS_FILE_ENTRIES) && (CacheEntry->bHostsFileEntry == FALSE))) + DnsIntCacheRemoveEntryItem(CacheEntry); /* Move to the next entry */ - Entry = DnsCache.RecordList.Flink; + Entry = NextEntry; } /* Unlock the cache */ DnsCacheUnlock(); + + return ERROR_SUCCESS; } DNS_STATUS @@ -178,11 +185,14 @@ DnsIntCacheRemoveEntryByName(LPCWSTR Name) } VOID -DnsIntCacheAddEntry(PDNS_RECORDW Record) +DnsIntCacheAddEntry( + _In_ PDNS_RECORDW Record, + _In_ BOOL bHostsFileEntry) { PRESOLVER_CACHE_ENTRY Entry; - DPRINT("DnsIntCacheAddEntry(%p)\n", Record); + DPRINT("DnsIntCacheAddEntry(%p %u)\n", + Record, bHostsFileEntry); DPRINT("Name: %S\n", Record->pName); DPRINT("TTL: %lu\n", Record->dwTtl); @@ -195,6 +205,7 @@ DnsIntCacheAddEntry(PDNS_RECORDW Record) if (!Entry) return; + Entry->bHostsFileEntry = bHostsFileEntry; Entry->Record = DnsRecordSetCopyEx(Record, DnsCharSetUnicode, DnsCharSetUnicode); /* Insert it to our List */ diff --git a/base/services/dnsrslvr/hostsfile.c b/base/services/dnsrslvr/hostsfile.c index 1c80dc0cffb..62554b91aa2 100644 --- a/base/services/dnsrslvr/hostsfile.c +++ b/base/services/dnsrslvr/hostsfile.c @@ -113,7 +113,7 @@ AddIpv4HostEntries( /* Prepare the PTR record */ swprintf(szReverseName, - L"%u.%u.%u.%u.in-addr.arpa", + L"%u.%u.%u.%u.in-addr.arpa.", pAddress->S_un.S_un_b.s_b4, pAddress->S_un.S_un_b.s_b3, pAddress->S_un.S_un_b.s_b2, @@ -130,8 +130,8 @@ AddIpv4HostEntries( PtrRecord.Data.PTR.pNameHost = pszHostName; - DnsIntCacheAddEntry(&ARecord); - DnsIntCacheAddEntry(&PtrRecord); + DnsIntCacheAddEntry(&ARecord, TRUE); + DnsIntCacheAddEntry(&PtrRecord, TRUE); } @@ -171,7 +171,7 @@ AddIpv6HostEntries( szReverseName[j + 2] = szHexChar[(pAddress->u.Byte[k] >> 4) & 0xF]; szReverseName[j + 3] = L'.'; } - wcscat(szReverseName, L"ip6.arpa"); + wcscat(szReverseName, L"ip6.arpa."); ZeroMemory(&PtrRecord, sizeof(DNS_RECORDW)); @@ -184,8 +184,8 @@ AddIpv6HostEntries( PtrRecord.Data.PTR.pNameHost = pszHostName; - DnsIntCacheAddEntry(&AAAARecord); - DnsIntCacheAddEntry(&PtrRecord); + DnsIntCacheAddEntry(&AAAARecord, TRUE); + DnsIntCacheAddEntry(&PtrRecord, TRUE); } diff --git a/base/services/dnsrslvr/precomp.h b/base/services/dnsrslvr/precomp.h index 81189cda9e6..2b7e5f35dd6 100644 --- a/base/services/dnsrslvr/precomp.h +++ b/base/services/dnsrslvr/precomp.h @@ -27,6 +27,7 @@ typedef struct _RESOLVER_CACHE_ENTRY { LIST_ENTRY CacheLink; + BOOL bHostsFileEntry; PDNS_RECORDW Record; } RESOLVER_CACHE_ENTRY, *PRESOLVER_CACHE_ENTRY; @@ -42,7 +43,14 @@ typedef struct _RESOLVER_CACHE VOID DnsIntCacheInitialize(VOID); VOID DnsIntCacheRemoveEntryItem(PRESOLVER_CACHE_ENTRY CacheEntry); VOID DnsIntCacheFree(VOID); -VOID DnsIntCacheFlush(VOID); + +#define CACHE_FLUSH_HOSTS_FILE_ENTRIES 0x00000001 +#define CACHE_FLUSH_NON_HOSTS_FILE_ENTRIES 0x00000002 +#define CACHE_FLUSH_ALL 0x00000003 + +DNS_STATUS +DnsIntCacheFlush( + _In_ ULONG ulFlags); DNS_STATUS DnsIntCacheGetEntryByName( @@ -51,8 +59,14 @@ DnsIntCacheGetEntryByName( DWORD dwFlags, PDNS_RECORDW *Record); -VOID DnsIntCacheAddEntry(PDNS_RECORDW Record); -BOOL DnsIntCacheRemoveEntryByName(LPCWSTR Name); +VOID +DnsIntCacheAddEntry( + _In_ PDNS_RECORDW Record, + _In_ BOOL bHostsFileEntry); + +BOOL +DnsIntCacheRemoveEntryByName( + _In_ LPCWSTR Name); DNS_STATUS DnsIntCacheGetEntries( diff --git a/base/services/dnsrslvr/rpcserver.c b/base/services/dnsrslvr/rpcserver.c index f79850ddb06..59e91cb4791 100644 --- a/base/services/dnsrslvr/rpcserver.c +++ b/base/services/dnsrslvr/rpcserver.c @@ -62,11 +62,10 @@ __stdcall R_ResolverFlushCache( _In_ DNSRSLVR_HANDLE pwszServerName) { - DPRINT("R_ResolverFlushCache()\n"); + DPRINT("R_ResolverFlushCache(%S)\n", + pwszServerName); - // FIXME Should store (and flush) entries by server handle - DnsIntCacheFlush(); - return ERROR_SUCCESS; + return DnsIntCacheFlush(CACHE_FLUSH_NON_HOSTS_FILE_ENTRIES); } @@ -126,7 +125,7 @@ R_ResolverQuery( if (Status == ERROR_SUCCESS) { DPRINT("DNS query successful!\n"); - DnsIntCacheAddEntry(*ppResultRecords); + DnsIntCacheAddEntry(*ppResultRecords, FALSE); } } }