Reactos

[DNSRSLVR] R_ResolverFlushCache should only flush cached records which were not read from the hosts file

+47 -23
+20 -9
base/services/dnsrslvr/cache.c
··· 44 44 if (!DnsCache.RecordList.Flink) 45 45 return; 46 46 47 - DnsIntCacheFlush(); 47 + DnsIntCacheFlush(CACHE_FLUSH_ALL); 48 48 49 49 DeleteCriticalSection(&DnsCache.Lock); 50 50 DnsCacheInitialized = FALSE; ··· 65 65 HeapFree(GetProcessHeap(), 0, CacheEntry); 66 66 } 67 67 68 - VOID 69 - DnsIntCacheFlush(VOID) 68 + DNS_STATUS 69 + DnsIntCacheFlush( 70 + _In_ ULONG ulFlags) 70 71 { 71 - PLIST_ENTRY Entry; 72 + PLIST_ENTRY Entry, NextEntry; 72 73 PRESOLVER_CACHE_ENTRY CacheEntry; 73 74 74 - DPRINT("DnsIntCacheFlush()\n"); 75 + DPRINT("DnsIntCacheFlush(%lu)\n", ulFlags); 75 76 76 77 /* Lock the cache */ 77 78 DnsCacheLock(); ··· 80 81 Entry = DnsCache.RecordList.Flink; 81 82 while (Entry != &DnsCache.RecordList) 82 83 { 84 + NextEntry = Entry->Flink; 85 + 83 86 /* Get this entry */ 84 87 CacheEntry = CONTAINING_RECORD(Entry, RESOLVER_CACHE_ENTRY, CacheLink); 85 88 86 89 /* Remove it from list */ 87 - DnsIntCacheRemoveEntryItem(CacheEntry); 90 + if (((ulFlags & CACHE_FLUSH_HOSTS_FILE_ENTRIES) && (CacheEntry->bHostsFileEntry != FALSE)) || 91 + ((ulFlags & CACHE_FLUSH_NON_HOSTS_FILE_ENTRIES) && (CacheEntry->bHostsFileEntry == FALSE))) 92 + DnsIntCacheRemoveEntryItem(CacheEntry); 88 93 89 94 /* Move to the next entry */ 90 - Entry = DnsCache.RecordList.Flink; 95 + Entry = NextEntry; 91 96 } 92 97 93 98 /* Unlock the cache */ 94 99 DnsCacheUnlock(); 100 + 101 + return ERROR_SUCCESS; 95 102 } 96 103 97 104 DNS_STATUS ··· 178 185 } 179 186 180 187 VOID 181 - DnsIntCacheAddEntry(PDNS_RECORDW Record) 188 + DnsIntCacheAddEntry( 189 + _In_ PDNS_RECORDW Record, 190 + _In_ BOOL bHostsFileEntry) 182 191 { 183 192 PRESOLVER_CACHE_ENTRY Entry; 184 193 185 - DPRINT("DnsIntCacheAddEntry(%p)\n", Record); 194 + DPRINT("DnsIntCacheAddEntry(%p %u)\n", 195 + Record, bHostsFileEntry); 186 196 187 197 DPRINT("Name: %S\n", Record->pName); 188 198 DPRINT("TTL: %lu\n", Record->dwTtl); ··· 195 205 if (!Entry) 196 206 return; 197 207 208 + Entry->bHostsFileEntry = bHostsFileEntry; 198 209 Entry->Record = DnsRecordSetCopyEx(Record, DnsCharSetUnicode, DnsCharSetUnicode); 199 210 200 211 /* Insert it to our List */
+6 -6
base/services/dnsrslvr/hostsfile.c
··· 113 113 114 114 /* Prepare the PTR record */ 115 115 swprintf(szReverseName, 116 - L"%u.%u.%u.%u.in-addr.arpa", 116 + L"%u.%u.%u.%u.in-addr.arpa.", 117 117 pAddress->S_un.S_un_b.s_b4, 118 118 pAddress->S_un.S_un_b.s_b3, 119 119 pAddress->S_un.S_un_b.s_b2, ··· 130 130 131 131 PtrRecord.Data.PTR.pNameHost = pszHostName; 132 132 133 - DnsIntCacheAddEntry(&ARecord); 134 - DnsIntCacheAddEntry(&PtrRecord); 133 + DnsIntCacheAddEntry(&ARecord, TRUE); 134 + DnsIntCacheAddEntry(&PtrRecord, TRUE); 135 135 } 136 136 137 137 ··· 171 171 szReverseName[j + 2] = szHexChar[(pAddress->u.Byte[k] >> 4) & 0xF]; 172 172 szReverseName[j + 3] = L'.'; 173 173 } 174 - wcscat(szReverseName, L"ip6.arpa"); 174 + wcscat(szReverseName, L"ip6.arpa."); 175 175 176 176 ZeroMemory(&PtrRecord, sizeof(DNS_RECORDW)); 177 177 ··· 184 184 185 185 PtrRecord.Data.PTR.pNameHost = pszHostName; 186 186 187 - DnsIntCacheAddEntry(&AAAARecord); 188 - DnsIntCacheAddEntry(&PtrRecord); 187 + DnsIntCacheAddEntry(&AAAARecord, TRUE); 188 + DnsIntCacheAddEntry(&PtrRecord, TRUE); 189 189 } 190 190 191 191
+17 -3
base/services/dnsrslvr/precomp.h
··· 27 27 typedef struct _RESOLVER_CACHE_ENTRY 28 28 { 29 29 LIST_ENTRY CacheLink; 30 + BOOL bHostsFileEntry; 30 31 PDNS_RECORDW Record; 31 32 } RESOLVER_CACHE_ENTRY, *PRESOLVER_CACHE_ENTRY; 32 33 ··· 42 43 VOID DnsIntCacheInitialize(VOID); 43 44 VOID DnsIntCacheRemoveEntryItem(PRESOLVER_CACHE_ENTRY CacheEntry); 44 45 VOID DnsIntCacheFree(VOID); 45 - VOID DnsIntCacheFlush(VOID); 46 + 47 + #define CACHE_FLUSH_HOSTS_FILE_ENTRIES 0x00000001 48 + #define CACHE_FLUSH_NON_HOSTS_FILE_ENTRIES 0x00000002 49 + #define CACHE_FLUSH_ALL 0x00000003 50 + 51 + DNS_STATUS 52 + DnsIntCacheFlush( 53 + _In_ ULONG ulFlags); 46 54 47 55 DNS_STATUS 48 56 DnsIntCacheGetEntryByName( ··· 51 59 DWORD dwFlags, 52 60 PDNS_RECORDW *Record); 53 61 54 - VOID DnsIntCacheAddEntry(PDNS_RECORDW Record); 55 - BOOL DnsIntCacheRemoveEntryByName(LPCWSTR Name); 62 + VOID 63 + DnsIntCacheAddEntry( 64 + _In_ PDNS_RECORDW Record, 65 + _In_ BOOL bHostsFileEntry); 66 + 67 + BOOL 68 + DnsIntCacheRemoveEntryByName( 69 + _In_ LPCWSTR Name); 56 70 57 71 DNS_STATUS 58 72 DnsIntCacheGetEntries(
+4 -5
base/services/dnsrslvr/rpcserver.c
··· 62 62 R_ResolverFlushCache( 63 63 _In_ DNSRSLVR_HANDLE pwszServerName) 64 64 { 65 - DPRINT("R_ResolverFlushCache()\n"); 65 + DPRINT("R_ResolverFlushCache(%S)\n", 66 + pwszServerName); 66 67 67 - // FIXME Should store (and flush) entries by server handle 68 - DnsIntCacheFlush(); 69 - return ERROR_SUCCESS; 68 + return DnsIntCacheFlush(CACHE_FLUSH_NON_HOSTS_FILE_ENTRIES); 70 69 } 71 70 72 71 ··· 126 125 if (Status == ERROR_SUCCESS) 127 126 { 128 127 DPRINT("DNS query successful!\n"); 129 - DnsIntCacheAddEntry(*ppResultRecords); 128 + DnsIntCacheAddEntry(*ppResultRecords, FALSE); 130 129 } 131 130 } 132 131 }