[DNSAPI][DNSRSLVR] Implement DnsGetCacheDataTable()

This commit is contained in:
Eric Kohl 2019-12-22 11:21:04 +01:00
parent 6499cf9e1a
commit 6c7878f35e
7 changed files with 124 additions and 14 deletions

View file

@ -203,3 +203,60 @@ DnsIntCacheAddEntry(PDNS_RECORDW Record)
/* Release the cache */
DnsCacheUnlock();
}
DNS_STATUS
DnsIntCacheGetEntries(
_Out_ DNS_CACHE_ENTRY **ppCacheEntries)
{
PRESOLVER_CACHE_ENTRY CacheEntry;
PLIST_ENTRY NextEntry;
PDNS_CACHE_ENTRY pLastEntry = NULL, pNewEntry;
/* Lock the cache */
DnsCacheLock();
*ppCacheEntries = NULL;
NextEntry = DnsCache.RecordList.Flink;
while (NextEntry != &DnsCache.RecordList)
{
/* Get the Current Entry */
CacheEntry = CONTAINING_RECORD(NextEntry, RESOLVER_CACHE_ENTRY, CacheLink);
DPRINT("1 %S %lu\n", CacheEntry->Record->pName, CacheEntry->Record->wType);
if (CacheEntry->Record->pNext)
{
DPRINT("2 %S %lu\n", CacheEntry->Record->pNext->pName, CacheEntry->Record->pNext->wType);
}
pNewEntry = midl_user_allocate(sizeof(DNS_CACHE_ENTRY));
if (pNewEntry == NULL)
{
return ERROR_OUTOFMEMORY;
}
pNewEntry->pszName = midl_user_allocate((wcslen(CacheEntry->Record->pName) + 1) * sizeof(WCHAR));
if (pNewEntry->pszName == NULL)
{
return ERROR_OUTOFMEMORY;
}
wcscpy(pNewEntry->pszName, CacheEntry->Record->pName);
pNewEntry->wType1 = CacheEntry->Record->wType;
pNewEntry->wType2 = 0;
pNewEntry->wFlags = 0;
if (pLastEntry == NULL)
*ppCacheEntries = pNewEntry;
else
pLastEntry->pNext = pNewEntry;
pLastEntry = pNewEntry;
NextEntry = NextEntry->Flink;
}
/* Release the cache */
DnsCacheUnlock();
return ERROR_SUCCESS;
}

View file

@ -54,6 +54,9 @@ DnsIntCacheGetEntryByName(
VOID DnsIntCacheAddEntry(PDNS_RECORDW Record);
BOOL DnsIntCacheRemoveEntryByName(LPCWSTR Name);
DNS_STATUS
DnsIntCacheGetEntries(
_Out_ DNS_CACHE_ENTRY **ppCacheEntries);
/* hostsfile.c */

View file

@ -41,6 +41,21 @@ RpcThreadRoutine(LPVOID lpParameter)
return 0;
}
/* Function: 0x00 */
DWORD
__stdcall
CRrReadCache(
_In_ DNSRSLVR_HANDLE pwszServerName,
_Out_ DNS_CACHE_ENTRY **ppCacheEntries)
{
DPRINT("CRrReadCache(%S %p)\n",
pwszServerName, ppCacheEntries);
return DnsIntCacheGetEntries(ppCacheEntries);
}
/* Function: 0x04 */
DWORD
__stdcall
@ -54,6 +69,7 @@ R_ResolverFlushCache(
return ERROR_SUCCESS;
}
/* Function: 0x07 */
DWORD
__stdcall

View file

@ -896,6 +896,41 @@ DnsFlushResolverCache(VOID)
return (Status == ERROR_SUCCESS);
}
BOOL
WINAPI
DnsGetCacheDataTable(
_Out_ PDNS_CACHE_ENTRY *DnsCache)
{
DNS_STATUS Status = ERROR_SUCCESS;
PDNS_CACHE_ENTRY CacheEntries = NULL;
if (DnsCache == NULL)
return FALSE;
RpcTryExcept
{
Status = CRrReadCache(NULL,
&CacheEntries);
DPRINT("CRrReadCache() returned %lu\n", Status);
}
RpcExcept(EXCEPTION_EXECUTE_HANDLER)
{
Status = RpcExceptionCode();
DPRINT1("Exception returned %lu\n", Status);
}
RpcEndExcept;
if (Status != ERROR_SUCCESS)
return FALSE;
if (CacheEntries == NULL)
return FALSE;
*DnsCache = CacheEntries;
return TRUE;
}
DWORD
WINAPI
GetCurrentTimeInSeconds(VOID)

View file

@ -266,15 +266,6 @@ DnsGetBufferLengthForStringCopy()
return ERROR_OUTOFMEMORY;
}
BOOL
WINAPI
DnsGetCacheDataTable(
_Out_ PDNS_CACHE_ENTRY *DnsCache)
{
UNIMPLEMENTED;
return TRUE;
}
DNS_STATUS WINAPI
DnsGetDnsServerList()
{

View file

@ -28,7 +28,11 @@ typedef [handle, string] LPWSTR DNSRSLVR_HANDLE;
interface DnsResolver
{
/* Function: 0x00 */
/* CRrReadCache */
DWORD
__stdcall
CRrReadCache(
[in, unique, string] DNSRSLVR_HANDLE pwszServerName,
[out] DNS_CACHE_ENTRY **ppCacheEntries);
/* Function: 0x01 */
/* CRrReadCacheEntry */
@ -56,10 +60,10 @@ interface DnsResolver
__stdcall
R_ResolverQuery(
[in, unique, string] DNSRSLVR_HANDLE pwszServerName,
[in, unique, string] LPCWSTR pwsName,
[in] WORD wType,
[in] DWORD Flags,
[in, out] DWORD *dwRecords,
[in, unique, string] LPCWSTR pwsName,
[in] WORD wType,
[in] DWORD Flags,
[in, out] DWORD *dwRecords,
[out] DNS_RECORDW **ppResultRecords);
/* Function: 0x08 */

View file

@ -8,7 +8,11 @@ extern "C" {
typedef struct _DNS_CACHE_ENTRY
{
struct _DNS_CACHE_ENTRY *pNext; /* Pointer to next entry */
#if defined(__midl) || defined(__WIDL__)
[string] PWSTR pszName; /* DNS Record Name */
#else
PWSTR pszName; /* DNS Record Name */
#endif
unsigned short wType1; /* DNS Record Type 1 */
unsigned short wType2; /* DNS Record Type 2 */
unsigned short wFlags; /* DNS Record Flags */