[DNSRSLVR][DNSAPI] Enable the DNS resolver cache
authorEric Kohl <eric.kohl@reactos.org>
Sun, 10 Nov 2019 14:28:42 +0000 (15:28 +0100)
committerEric Kohl <eric.kohl@reactos.org>
Sun, 10 Nov 2019 14:28:42 +0000 (15:28 +0100)
- Fix the IDL file to return DNS records properly
- Reroute the DNS query call path: DNSQuery->R_ResolverQuery->Query_Main

DNS records get cached and 'ipconfig /flushdns' works as expected.

CORE-12159

base/services/dnsrslvr/precomp.h
base/services/dnsrslvr/rpcserver.c
dll/win32/dnsapi/dnsapi.spec
dll/win32/dnsapi/dnsapi/query.c
sdk/include/reactos/idl/dnsrslvr.idl
sdk/include/reactos/windns_undoc.h

index 0a11db5..3983d31 100644 (file)
@@ -11,6 +11,7 @@
 #include <winbase.h>
 #include <winsvc.h>
 #include <windns.h>
 #include <winbase.h>
 #include <winsvc.h>
 #include <windns.h>
+#include <windns_undoc.h>
 
 #include <ndk/rtlfuncs.h>
 #include <ndk/obfuncs.h>
 
 #include <ndk/rtlfuncs.h>
 #include <ndk/obfuncs.h>
index 0cb5c1f..96e398c 100644 (file)
@@ -45,6 +45,8 @@ DWORD
 R_ResolverFlushCache(
     DNSRSLVR_HANDLE pwszServerName)
 {
 R_ResolverFlushCache(
     DNSRSLVR_HANDLE pwszServerName)
 {
+    DPRINT("R_ResolverFlushCache()\n");
+
     // FIXME Should store (and flush) entries by server handle
     DnsIntCacheFlush();
     return 0;
     // FIXME Should store (and flush) entries by server handle
     DnsIntCacheFlush();
     return 0;
@@ -52,65 +54,61 @@ R_ResolverFlushCache(
 
 DWORD
 R_ResolverQuery(
 
 DWORD
 R_ResolverQuery(
-    DNSRSLVR_HANDLE pwszServerName,
-    LPCWSTR pwsName,
+    DNSRSLVR_HANDLE pszServerName,
+    LPCWSTR pszName,
     WORD wType,
     WORD wType,
-    DWORD Flags,
+    DWORD dwFlags,
     DWORD *dwRecords,
     DNS_RECORDW **ppResultRecords)
 {
     DWORD *dwRecords,
     DNS_RECORDW **ppResultRecords)
 {
-#if 0
-    DNS_QUERY_REQUEST  QueryRequest = { 0 };
-    DNS_QUERY_RESULT   QueryResults = { 0 };
-#endif
-    DNS_STATUS         Status;
-    PDNS_RECORDW       Record;
+    PDNS_RECORDW Record;
+    DNS_STATUS Status;
+
+    DPRINT("R_ResolverQuery(%S %S %x %lx %p %p)\n",
+           pszServerName, pszName, wType, dwFlags, dwRecords, ppResultRecords);
 
 
-    DPRINT1("R_ResolverQuery %p %p %x %lx %p %p\n",
-            pwszServerName, pwsName, wType, Flags, dwRecords, ppResultRecords);
+    if (pszName == NULL || wType == 0 || ppResultRecords == NULL)
+        return ERROR_INVALID_PARAMETER;
 
 
-    if (!pwszServerName || !pwsName || !wType || !ppResultRecords)
+    if ((dwFlags & DNS_QUERY_WIRE_ONLY) != 0 && (dwFlags & DNS_QUERY_NO_WIRE_QUERY) != 0)
         return ERROR_INVALID_PARAMETER;
 
         return ERROR_INVALID_PARAMETER;
 
-    // FIXME Should lookup entries by server handle
-    if (DnsIntCacheGetEntryFromName(pwsName, ppResultRecords))
+    if (DnsIntCacheGetEntryFromName(pszName, ppResultRecords))
     {
     {
+        DPRINT("DNS cache query successful!\n");
         Status = ERROR_SUCCESS;
     }
     else
     {
         Status = ERROR_SUCCESS;
     }
     else
     {
-#if 0
-        QueryRequest.Version = DNS_QUERY_REQUEST_VERSION1;
-        QueryRequest.QueryType = wType;
-        QueryRequest.QueryName = pwsName;
-        QueryRequest.QueryOptions = Flags;
-        QueryResults.Version = DNS_QUERY_REQUEST_VERSION1;
-
-        Status = DnsQueryEx(&QueryRequest, &QueryResults, NULL);
+        DPRINT("DNS query!\n");
+        Status = Query_Main(pszName,
+                            wType,
+                            dwFlags,
+                            ppResultRecords);
         if (Status == ERROR_SUCCESS)
         {
         if (Status == ERROR_SUCCESS)
         {
-            // FIXME Should store (and flush) entries by server handle
-            DnsIntCacheAddEntry(QueryResults.pQueryRecords);
-            *ppResultRecords = QueryResults.pQueryRecords;
+            DPRINT("DNS query successful!\n");
+            DnsIntCacheAddEntry(*ppResultRecords);
         }
         }
-#endif
     }
 
     if (dwRecords)
     }
 
     if (dwRecords)
+    {
         *dwRecords = 0;
 
         *dwRecords = 0;
 
-    if (Status == ERROR_SUCCESS)
-    {
-        Record = *ppResultRecords;
-        while (Record)
+        if (Status == ERROR_SUCCESS)
         {
         {
-            if (dwRecords)
+            Record = *ppResultRecords;
+            while (Record)
+            {
+                DPRINT("Record: %S\n", Record->pName);
                 (*dwRecords)++;
                 (*dwRecords)++;
-            Record = Record->pNext;
+                Record = Record->pNext;
+            }
         }
     }
 
         }
     }
 
-    DPRINT1("R_ResolverQuery result %ld %ld\n", Status, *dwRecords);
+    DPRINT("R_ResolverQuery result %ld %ld\n", Status, *dwRecords);
 
     return Status;
 }
 
     return Status;
 }
index bb69e12..afc309e 100644 (file)
@@ -82,7 +82,6 @@
 @ stdcall DnsNameCompareEx_W()
 @ stdcall DnsNameCompare_A(str str)
 @ stdcall DnsNameCompare_W(wstr wstr)
 @ stdcall DnsNameCompareEx_W()
 @ stdcall DnsNameCompare_A(str str)
 @ stdcall DnsNameCompare_W(wstr wstr)
-
 @ stdcall DnsNameCopy()
 @ stdcall DnsNameCopyAllocate()
 @ stdcall DnsNotifyResolver()
 @ stdcall DnsNameCopy()
 @ stdcall DnsNameCopyAllocate()
 @ stdcall DnsNotifyResolver()
 @ stub NetInfo_IsForUpdate
 @ stub NetInfo_ResetServerPriorities
 @ stub QueryDirectEx
 @ stub NetInfo_IsForUpdate
 @ stub NetInfo_ResetServerPriorities
 @ stub QueryDirectEx
-@ stub Query_Main
+@ stdcall Query_Main(wstr long long ptr)
 @ stub Reg_ReadGlobalsEx
 @ stub Reg_ReadGlobalsEx
index bc89c8d..d830e26 100644 (file)
@@ -164,7 +164,7 @@ DnsQuery_CodePage(UINT CodePage,
     PWCHAR Buffer;
     DNS_STATUS Status;
     PDNS_RECORD QueryResultWide;
     PWCHAR Buffer;
     DNS_STATUS Status;
     PDNS_RECORD QueryResultWide;
-    PDNS_RECORD ConvertedRecord = NULL, LastRecord = NULL;
+    PDNS_RECORD ConvertedRecord = 0, LastRecord = 0;
 
     if (Name == NULL)
         return ERROR_INVALID_PARAMETER;
 
     if (Name == NULL)
         return ERROR_INVALID_PARAMETER;
@@ -309,7 +309,7 @@ DnsQuery_CodePage(UINT CodePage,
     }
 
     if (LastRecord)
     }
 
     if (LastRecord)
-        LastRecord->pNext = NULL;
+        LastRecord->pNext = 0;
 
     /* The name */
     RtlFreeHeap(RtlGetProcessHeap(), 0, Buffer);
 
     /* The name */
     RtlFreeHeap(RtlGetProcessHeap(), 0, Buffer);
@@ -729,6 +729,41 @@ DnsQuery_W(LPCWSTR Name,
            PVOID Extra,
            PDNS_RECORD *QueryResultSet,
            PVOID *Reserved)
            PVOID Extra,
            PDNS_RECORD *QueryResultSet,
            PVOID *Reserved)
+{
+    DWORD dwRecords = 0;
+    DNS_STATUS Status = ERROR_SUCCESS;
+
+    DPRINT("DnsQuery_W()\n");
+
+    *QueryResultSet = NULL;
+
+    RpcTryExcept
+    {
+        Status = R_ResolverQuery(NULL,
+                                 Name,
+                                 Type,
+                                 Options,
+                                 &dwRecords,
+                                 (DNS_RECORDW **)QueryResultSet);
+        DPRINT("R_ResolverQuery() returned %lu\n", Status);
+    }
+    RpcExcept(EXCEPTION_EXECUTE_HANDLER)
+    {
+        Status = RpcExceptionCode();
+        DPRINT("Exception returned %lu\n", Status);
+    }
+    RpcEndExcept;
+
+    return Status;
+}
+
+
+DNS_STATUS
+WINAPI
+Query_Main(LPCWSTR Name,
+           WORD Type,
+           DWORD Options,
+           PDNS_RECORD *QueryResultSet)
 {
     adns_state astate;
     int quflags = (Options & DNS_QUERY_NO_RECURSION) == 0 ? adns_qf_search : 0;
 {
     adns_state astate;
     int quflags = (Options & DNS_QUERY_NO_RECURSION) == 0 ? adns_qf_search : 0;
@@ -750,10 +785,8 @@ DnsQuery_W(LPCWSTR Name,
         return ERROR_INVALID_PARAMETER;
     if (QueryResultSet == NULL)
         return ERROR_INVALID_PARAMETER;
         return ERROR_INVALID_PARAMETER;
     if (QueryResultSet == NULL)
         return ERROR_INVALID_PARAMETER;
-    if ((Options & DNS_QUERY_WIRE_ONLY) != 0 && (Options & DNS_QUERY_NO_WIRE_QUERY) != 0)
-        return ERROR_INVALID_PARAMETER;
 
 
-    *QueryResultSet = 0;
+    *QueryResultSet = NULL;
 
     switch (Type)
     {
 
     switch (Type)
     {
index 787e5c7..ce05145 100644 (file)
@@ -53,7 +53,7 @@ interface DnsResolver
         [in] WORD wType, 
         [in] DWORD Flags, 
         [in][out] DWORD *dwRecords, 
         [in] WORD wType, 
         [in] DWORD Flags, 
         [in][out] DWORD *dwRecords, 
-        [out][ref] DNS_RECORDW** ppResultRecords);
+        [out] DNS_RECORDW **ppResultRecords);
 
     /* Function: 0x08 */
     /* R_ResolverEnumCache */
 
     /* Function: 0x08 */
     /* R_ResolverEnumCache */
index cb2e5ab..56cc56d 100644 (file)
@@ -31,6 +31,14 @@ DNS_STATUS
 WINAPI
 GetCurrentTimeInSeconds(VOID);
 
 WINAPI
 GetCurrentTimeInSeconds(VOID);
 
+DNS_STATUS
+WINAPI
+Query_Main(
+    LPCWSTR Name,
+    WORD Type,
+    DWORD Options,
+    PDNS_RECORD *QueryResultSet);
+
 #endif /* __WIDL__ */
 
 #ifdef __cplusplus
 #endif /* __WIDL__ */
 
 #ifdef __cplusplus