https://git.reactos.org/?p=reactos.git;a=commitdiff;h=6c7878f35e086360ab9bc…
commit 6c7878f35e086360ab9bcbd8f1dfd4218f35d74f
Author: Eric Kohl <eric.kohl(a)reactos.org>
AuthorDate: Sun Dec 22 11:21:04 2019 +0100
Commit: Eric Kohl <eric.kohl(a)reactos.org>
CommitDate: Sun Dec 22 11:21:04 2019 +0100
[DNSAPI][DNSRSLVR] Implement DnsGetCacheDataTable()
---
base/services/dnsrslvr/cache.c | 57 ++++++++++++++++++++++++++++++++++++
base/services/dnsrslvr/precomp.h | 3 ++
base/services/dnsrslvr/rpcserver.c | 16 ++++++++++
dll/win32/dnsapi/query.c | 35 ++++++++++++++++++++++
dll/win32/dnsapi/stubs.c | 9 ------
sdk/include/reactos/idl/dnsrslvr.idl | 14 +++++----
sdk/include/reactos/windns_undoc.h | 4 +++
7 files changed, 124 insertions(+), 14 deletions(-)
diff --git a/base/services/dnsrslvr/cache.c b/base/services/dnsrslvr/cache.c
index 748a1599383..af4cc2a8597 100644
--- a/base/services/dnsrslvr/cache.c
+++ b/base/services/dnsrslvr/cache.c
@@ -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;
+}
diff --git a/base/services/dnsrslvr/precomp.h b/base/services/dnsrslvr/precomp.h
index c0bbeecd30e..81189cda9e6 100644
--- a/base/services/dnsrslvr/precomp.h
+++ b/base/services/dnsrslvr/precomp.h
@@ -54,6 +54,9 @@ DnsIntCacheGetEntryByName(
VOID DnsIntCacheAddEntry(PDNS_RECORDW Record);
BOOL DnsIntCacheRemoveEntryByName(LPCWSTR Name);
+DNS_STATUS
+DnsIntCacheGetEntries(
+ _Out_ DNS_CACHE_ENTRY **ppCacheEntries);
/* hostsfile.c */
diff --git a/base/services/dnsrslvr/rpcserver.c b/base/services/dnsrslvr/rpcserver.c
index cb4b9476b04..f79850ddb06 100644
--- a/base/services/dnsrslvr/rpcserver.c
+++ b/base/services/dnsrslvr/rpcserver.c
@@ -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
diff --git a/dll/win32/dnsapi/query.c b/dll/win32/dnsapi/query.c
index 3ffaa41dffe..f16d8ec883f 100644
--- a/dll/win32/dnsapi/query.c
+++ b/dll/win32/dnsapi/query.c
@@ -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)
diff --git a/dll/win32/dnsapi/stubs.c b/dll/win32/dnsapi/stubs.c
index 0a4bf59db55..7d946ababfa 100644
--- a/dll/win32/dnsapi/stubs.c
+++ b/dll/win32/dnsapi/stubs.c
@@ -266,15 +266,6 @@ DnsGetBufferLengthForStringCopy()
return ERROR_OUTOFMEMORY;
}
-BOOL
-WINAPI
-DnsGetCacheDataTable(
- _Out_ PDNS_CACHE_ENTRY *DnsCache)
-{
- UNIMPLEMENTED;
- return TRUE;
-}
-
DNS_STATUS WINAPI
DnsGetDnsServerList()
{
diff --git a/sdk/include/reactos/idl/dnsrslvr.idl b/sdk/include/reactos/idl/dnsrslvr.idl
index cae2e196e62..91cad5a52eb 100644
--- a/sdk/include/reactos/idl/dnsrslvr.idl
+++ b/sdk/include/reactos/idl/dnsrslvr.idl
@@ -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 */
diff --git a/sdk/include/reactos/windns_undoc.h b/sdk/include/reactos/windns_undoc.h
index 1b07f61f94a..ece0d38954f 100644
--- a/sdk/include/reactos/windns_undoc.h
+++ b/sdk/include/reactos/windns_undoc.h
@@ -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 */