if (!DnsCache.RecordList.Flink)
return;
- DnsIntCacheFlush();
+ DnsIntCacheFlush(CACHE_FLUSH_ALL);
DeleteCriticalSection(&DnsCache.Lock);
DnsCacheInitialized = FALSE;
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();
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
}
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);
if (!Entry)
return;
+ Entry->bHostsFileEntry = bHostsFileEntry;
Entry->Record = DnsRecordSetCopyEx(Record, DnsCharSetUnicode, DnsCharSetUnicode);
/* Insert it to our List */
/* 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,
PtrRecord.Data.PTR.pNameHost = pszHostName;
- DnsIntCacheAddEntry(&ARecord);
- DnsIntCacheAddEntry(&PtrRecord);
+ DnsIntCacheAddEntry(&ARecord, TRUE);
+ DnsIntCacheAddEntry(&PtrRecord, TRUE);
}
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));
PtrRecord.Data.PTR.pNameHost = pszHostName;
- DnsIntCacheAddEntry(&AAAARecord);
- DnsIntCacheAddEntry(&PtrRecord);
+ DnsIntCacheAddEntry(&AAAARecord, TRUE);
+ DnsIntCacheAddEntry(&PtrRecord, TRUE);
}
typedef struct _RESOLVER_CACHE_ENTRY
{
LIST_ENTRY CacheLink;
+ BOOL bHostsFileEntry;
PDNS_RECORDW Record;
} RESOLVER_CACHE_ENTRY, *PRESOLVER_CACHE_ENTRY;
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(
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(
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);
}
if (Status == ERROR_SUCCESS)
{
DPRINT("DNS query successful!\n");
- DnsIntCacheAddEntry(*ppResultRecords);
+ DnsIntCacheAddEntry(*ppResultRecords, FALSE);
}
}
}