https://git.reactos.org/?p=reactos.git;a=commitdiff;h=b79246c534dbcf75f290c…
commit b79246c534dbcf75f290c6c1352eb715addeec14
Author: Eric Kohl <eric.kohl(a)reactos.org>
AuthorDate: Sun Oct 27 20:38:25 2019 +0100
Commit: Eric Kohl <eric.kohl(a)reactos.org>
CommitDate: Sun Oct 27 20:38:25 2019 +0100
[DNSAPI] Add the Resolver Service RPC client code and implement
DnsFlushResolverCache()
Patch by Peter Hater and Christoph von Wittich.
Slightly modified by me.
CORE-12159
---
dll/win32/dnsapi/CMakeLists.txt | 11 ++++--
dll/win32/dnsapi/dnsapi/precomp.h | 2 ++
dll/win32/dnsapi/dnsapi/query.c | 23 ++++++++++++
dll/win32/dnsapi/dnsapi/rpc.c | 75 +++++++++++++++++++++++++++++++++++++++
dll/win32/dnsapi/dnsapi/stubs.c | 7 ----
5 files changed, 108 insertions(+), 10 deletions(-)
diff --git a/dll/win32/dnsapi/CMakeLists.txt b/dll/win32/dnsapi/CMakeLists.txt
index 2dcfaa0a84b..a0edb35c99b 100644
--- a/dll/win32/dnsapi/CMakeLists.txt
+++ b/dll/win32/dnsapi/CMakeLists.txt
@@ -1,9 +1,12 @@
include_directories(
include
+ ${REACTOS_SOURCE_DIR}/sdk/include/reactos/idl
${REACTOS_SOURCE_DIR}/sdk/lib/3rdparty/adns/src
${REACTOS_SOURCE_DIR}/sdk/lib/3rdparty/adns/adns_win32)
+add_rpc_files(client ${REACTOS_SOURCE_DIR}/sdk/include/reactos/idl/dnsrslvr.idl)
+
add_definitions(-DADNS_JGAA_WIN32 -D_CRT_NO_POSIX_ERROR_CODES)
spec2def(dnsapi.dll dnsapi.spec ADD_IMPORTLIB)
@@ -14,8 +17,10 @@ list(APPEND SOURCE
dnsapi/names.c
dnsapi/query.c
dnsapi/record.c
+ dnsapi/rpc.c
dnsapi/stubs.c
- dnsapi/precomp.h)
+ dnsapi/precomp.h
+ ${CMAKE_CURRENT_BINARY_DIR}/dnsrslvr_c.c)
add_library(dnsapi MODULE
${SOURCE}
@@ -23,7 +28,7 @@ add_library(dnsapi MODULE
${CMAKE_CURRENT_BINARY_DIR}/dnsapi.def)
set_module_type(dnsapi win32dll)
-target_link_libraries(dnsapi adns)
-add_importlibs(dnsapi advapi32 user32 ws2_32 iphlpapi msvcrt kernel32 ntdll)
+target_link_libraries(dnsapi adns ${PSEH_LIB})
+add_importlibs(dnsapi advapi32 rpcrt4 user32 ws2_32 iphlpapi msvcrt kernel32 ntdll)
add_pch(dnsapi dnsapi/precomp.h SOURCE)
add_cd_file(TARGET dnsapi DESTINATION reactos/system32 FOR all)
diff --git a/dll/win32/dnsapi/dnsapi/precomp.h b/dll/win32/dnsapi/dnsapi/precomp.h
index 687e67f5947..e792a4779fa 100644
--- a/dll/win32/dnsapi/dnsapi/precomp.h
+++ b/dll/win32/dnsapi/dnsapi/precomp.h
@@ -25,6 +25,8 @@
#define NTOS_MODE_USER
#include <ndk/rtlfuncs.h>
+#include <dnsrslvr_c.h>
+
/* Internal DNSAPI Headers */
#include <internal/windns.h>
diff --git a/dll/win32/dnsapi/dnsapi/query.c b/dll/win32/dnsapi/dnsapi/query.c
index 7b40b09a867..2daa2803663 100644
--- a/dll/win32/dnsapi/dnsapi/query.c
+++ b/dll/win32/dnsapi/dnsapi/query.c
@@ -1072,3 +1072,26 @@ DnsIntFreeRecordList(PDNS_RECORD ToDelete)
ToDelete = next;
}
}
+
+BOOL
+WINAPI
+DnsFlushResolverCache(VOID)
+{
+ DNS_STATUS Status = ERROR_SUCCESS;
+
+ DPRINT("DnsFlushResolverCache()\n");
+
+ RpcTryExcept
+ {
+ Status = R_ResolverFlushCache(NULL);
+ DPRINT("R_ResolverFlushCache() returned %lu\n", Status);
+ }
+ RpcExcept(EXCEPTION_EXECUTE_HANDLER)
+ {
+ Status = RpcExceptionCode();
+ DPRINT("Exception returned %lu\n", Status);
+ }
+ RpcEndExcept;
+
+ return (Status == ERROR_SUCCESS);
+}
diff --git a/dll/win32/dnsapi/dnsapi/rpc.c b/dll/win32/dnsapi/dnsapi/rpc.c
new file mode 100644
index 00000000000..528f87e6b7e
--- /dev/null
+++ b/dll/win32/dnsapi/dnsapi/rpc.c
@@ -0,0 +1,75 @@
+#define WIN32_NO_STATUS
+#define _INC_WINDOWS
+#define COM_NO_WINDOWS_H
+#include <stdarg.h>
+#include <windef.h>
+#include <winbase.h>
+#include <dnsrslvr_c.h>
+
+#define NDEBUG
+#include <debug.h>
+
+handle_t __RPC_USER
+DNSRSLVR_HANDLE_bind(DNSRSLVR_HANDLE pszMachineName)
+{
+ handle_t hBinding = NULL;
+ LPWSTR pszStringBinding;
+ RPC_STATUS Status;
+
+ DPRINT1("DNSRSLVR_HANDLE_bind(%S)\n", pszMachineName);
+
+ Status = RpcStringBindingComposeW(NULL,
+ L"ncalrpc",
+ pszMachineName,
+ L"DNSResolver",
+ NULL,
+ &pszStringBinding);
+ if (Status != RPC_S_OK)
+ {
+ DPRINT1("RpcStringBindingCompose returned 0x%x\n", Status);
+ return NULL;
+ }
+
+ /* Set the binding handle that will be used to bind to the server. */
+ Status = RpcBindingFromStringBindingW(pszStringBinding,
+ &hBinding);
+ if (Status != RPC_S_OK)
+ {
+ DPRINT1("RpcBindingFromStringBinding returned 0x%x\n", Status);
+ }
+
+ Status = RpcStringFreeW(&pszStringBinding);
+ if (Status != RPC_S_OK)
+ {
+ DPRINT1("RpcStringFree returned 0x%x\n", Status);
+ }
+
+ return hBinding;
+}
+
+void __RPC_USER
+DNSRSLVR_HANDLE_unbind(DNSRSLVR_HANDLE pszMachineName,
+ handle_t hBinding)
+{
+ RPC_STATUS Status;
+
+ DPRINT("DNSRSLVR_HANDLE_unbind(%S)\n", pszMachineName);
+
+ Status = RpcBindingFree(&hBinding);
+ if (Status != RPC_S_OK)
+ {
+ DPRINT1("RpcBindingFree returned 0x%x\n", Status);
+ }
+}
+
+void __RPC_FAR * __RPC_USER
+midl_user_allocate(SIZE_T len)
+{
+ return HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, len);
+}
+
+void __RPC_USER
+midl_user_free(void __RPC_FAR * ptr)
+{
+ HeapFree(GetProcessHeap(), 0, ptr);
+}
\ No newline at end of file
diff --git a/dll/win32/dnsapi/dnsapi/stubs.c b/dll/win32/dnsapi/dnsapi/stubs.c
index 2832270d36b..f474f34695b 100644
--- a/dll/win32/dnsapi/dnsapi/stubs.c
+++ b/dll/win32/dnsapi/dnsapi/stubs.c
@@ -216,13 +216,6 @@ DnsFindAuthoritativeZone()
return ERROR_OUTOFMEMORY;
}
-BOOL WINAPI
-DnsFlushResolverCache(VOID)
-{
- UNIMPLEMENTED;
- return TRUE;
-}
-
BOOL WINAPI
DnsFlushResolverCacheEntry_A(PCSTR entry)
{