1d49d7b32SEric Kohl /*
2d49d7b32SEric Kohl * PROJECT: ReactOS DNS Resolver
3d49d7b32SEric Kohl * LICENSE: GPL - See COPYING in the top level directory
4d49d7b32SEric Kohl * FILE: base/services/dnsrslvr/rpcserver.c
5d49d7b32SEric Kohl * PURPOSE: RPC server interface
6d49d7b32SEric Kohl * COPYRIGHT: Copyright 2016 Christoph von Wittich
7d49d7b32SEric Kohl */
8d49d7b32SEric Kohl
9d49d7b32SEric Kohl #include "precomp.h"
10d49d7b32SEric Kohl
11d49d7b32SEric Kohl #define NDEBUG
12d49d7b32SEric Kohl #include <debug.h>
13d49d7b32SEric Kohl
14d49d7b32SEric Kohl DWORD
15d49d7b32SEric Kohl WINAPI
RpcThreadRoutine(LPVOID lpParameter)16d49d7b32SEric Kohl RpcThreadRoutine(LPVOID lpParameter)
17d49d7b32SEric Kohl {
18d49d7b32SEric Kohl RPC_STATUS Status;
19d49d7b32SEric Kohl
20d49d7b32SEric Kohl Status = RpcServerUseProtseqEpW(L"ncalrpc", 20, L"DNSResolver", NULL);
21d49d7b32SEric Kohl if (Status != RPC_S_OK)
22d49d7b32SEric Kohl {
23d49d7b32SEric Kohl DPRINT("RpcServerUseProtseqEpW() failed (Status %lx)\n", Status);
24d49d7b32SEric Kohl return 0;
25d49d7b32SEric Kohl }
26d49d7b32SEric Kohl
27d49d7b32SEric Kohl Status = RpcServerRegisterIf(DnsResolver_v2_0_s_ifspec, NULL, NULL);
28d49d7b32SEric Kohl if (Status != RPC_S_OK)
29d49d7b32SEric Kohl {
30d49d7b32SEric Kohl DPRINT("RpcServerRegisterIf() failed (Status %lx)\n", Status);
31d49d7b32SEric Kohl return 0;
32d49d7b32SEric Kohl }
33d49d7b32SEric Kohl
34d49d7b32SEric Kohl Status = RpcServerListen(1, RPC_C_LISTEN_MAX_CALLS_DEFAULT, 0);
35d49d7b32SEric Kohl if (Status != RPC_S_OK)
36d49d7b32SEric Kohl {
37d49d7b32SEric Kohl DPRINT("RpcServerListen() failed (Status %lx)\n", Status);
38d49d7b32SEric Kohl }
39d49d7b32SEric Kohl
40d49d7b32SEric Kohl DPRINT("RpcServerListen finished\n");
41d49d7b32SEric Kohl return 0;
42d49d7b32SEric Kohl }
43d49d7b32SEric Kohl
446c7878f3SEric Kohl
456c7878f3SEric Kohl /* Function: 0x00 */
466c7878f3SEric Kohl DWORD
476c7878f3SEric Kohl __stdcall
CRrReadCache(_In_ DNSRSLVR_HANDLE pwszServerName,_Out_ DNS_CACHE_ENTRY ** ppCacheEntries)486c7878f3SEric Kohl CRrReadCache(
496c7878f3SEric Kohl _In_ DNSRSLVR_HANDLE pwszServerName,
506c7878f3SEric Kohl _Out_ DNS_CACHE_ENTRY **ppCacheEntries)
516c7878f3SEric Kohl {
526c7878f3SEric Kohl DPRINT("CRrReadCache(%S %p)\n",
536c7878f3SEric Kohl pwszServerName, ppCacheEntries);
546c7878f3SEric Kohl
556c7878f3SEric Kohl return DnsIntCacheGetEntries(ppCacheEntries);
566c7878f3SEric Kohl }
576c7878f3SEric Kohl
586c7878f3SEric Kohl
59630f34a0SEric Kohl /* Function: 0x04 */
60d49d7b32SEric Kohl DWORD
61e92ad7f3SEric Kohl __stdcall
R_ResolverFlushCache(_In_ DNSRSLVR_HANDLE pszServerName)62d49d7b32SEric Kohl R_ResolverFlushCache(
63*894cc4acSEric Kohl _In_ DNSRSLVR_HANDLE pszServerName)
64d49d7b32SEric Kohl {
6517f932d7SEric Kohl DPRINT("R_ResolverFlushCache(%S)\n",
66*894cc4acSEric Kohl pszServerName);
67305035beSEric Kohl
6817f932d7SEric Kohl return DnsIntCacheFlush(CACHE_FLUSH_NON_HOSTS_FILE_ENTRIES);
69d49d7b32SEric Kohl }
70d49d7b32SEric Kohl
716c7878f3SEric Kohl
72*894cc4acSEric Kohl /* Function: 0x05 */
73*894cc4acSEric Kohl DWORD
74*894cc4acSEric Kohl __stdcall
R_ResolverFlushCacheEntry(_In_ DNSRSLVR_HANDLE pszServerName,_In_ LPCWSTR pszName,_In_ WORD wType)75*894cc4acSEric Kohl R_ResolverFlushCacheEntry(
76*894cc4acSEric Kohl _In_ DNSRSLVR_HANDLE pszServerName,
77*894cc4acSEric Kohl _In_ LPCWSTR pszName,
78*894cc4acSEric Kohl _In_ WORD wType)
79*894cc4acSEric Kohl {
80*894cc4acSEric Kohl DPRINT("R_ResolverFlushCacheEntry(%S %S %x)\n",
81*894cc4acSEric Kohl pszServerName, pszName, wType);
82*894cc4acSEric Kohl
83*894cc4acSEric Kohl if (pszName == NULL)
84*894cc4acSEric Kohl return ERROR_INVALID_PARAMETER;
85*894cc4acSEric Kohl
86*894cc4acSEric Kohl return DnsIntFlushCacheEntry(pszName, wType);
87*894cc4acSEric Kohl }
88*894cc4acSEric Kohl
89*894cc4acSEric Kohl
90630f34a0SEric Kohl /* Function: 0x07 */
91d49d7b32SEric Kohl DWORD
92e92ad7f3SEric Kohl __stdcall
R_ResolverQuery(_In_ DNSRSLVR_HANDLE pszServerName,_In_ LPCWSTR pszName,_In_ WORD wType,_In_ DWORD dwFlags,_Inout_ DWORD * dwRecords,_Out_ DNS_RECORDW ** ppResultRecords)93d49d7b32SEric Kohl R_ResolverQuery(
94630f34a0SEric Kohl _In_ DNSRSLVR_HANDLE pszServerName,
95630f34a0SEric Kohl _In_ LPCWSTR pszName,
96630f34a0SEric Kohl _In_ WORD wType,
97630f34a0SEric Kohl _In_ DWORD dwFlags,
98630f34a0SEric Kohl _Inout_ DWORD *dwRecords,
99630f34a0SEric Kohl _Out_ DNS_RECORDW **ppResultRecords)
100d49d7b32SEric Kohl {
101d49d7b32SEric Kohl PDNS_RECORDW Record;
102630f34a0SEric Kohl DNS_STATUS Status = ERROR_SUCCESS;
103d49d7b32SEric Kohl
104305035beSEric Kohl DPRINT("R_ResolverQuery(%S %S %x %lx %p %p)\n",
105305035beSEric Kohl pszServerName, pszName, wType, dwFlags, dwRecords, ppResultRecords);
106d49d7b32SEric Kohl
107305035beSEric Kohl if (pszName == NULL || wType == 0 || ppResultRecords == NULL)
108d49d7b32SEric Kohl return ERROR_INVALID_PARAMETER;
109d49d7b32SEric Kohl
110305035beSEric Kohl if ((dwFlags & DNS_QUERY_WIRE_ONLY) != 0 && (dwFlags & DNS_QUERY_NO_WIRE_QUERY) != 0)
111305035beSEric Kohl return ERROR_INVALID_PARAMETER;
112305035beSEric Kohl
113630f34a0SEric Kohl if (dwFlags & DNS_QUERY_WIRE_ONLY)
114d49d7b32SEric Kohl {
115630f34a0SEric Kohl DPRINT("DNS query!\n");
116630f34a0SEric Kohl Status = Query_Main(pszName,
117630f34a0SEric Kohl wType,
118630f34a0SEric Kohl dwFlags,
119630f34a0SEric Kohl ppResultRecords);
120630f34a0SEric Kohl }
121630f34a0SEric Kohl else if (dwFlags & DNS_QUERY_NO_WIRE_QUERY)
122630f34a0SEric Kohl {
123630f34a0SEric Kohl DPRINT("DNS cache query!\n");
124630f34a0SEric Kohl Status = DnsIntCacheGetEntryByName(pszName,
125630f34a0SEric Kohl wType,
126630f34a0SEric Kohl dwFlags,
127630f34a0SEric Kohl ppResultRecords);
128d49d7b32SEric Kohl }
129d49d7b32SEric Kohl else
130d49d7b32SEric Kohl {
131630f34a0SEric Kohl DPRINT("DNS cache query!\n");
132630f34a0SEric Kohl Status = DnsIntCacheGetEntryByName(pszName,
133630f34a0SEric Kohl wType,
134630f34a0SEric Kohl dwFlags,
135630f34a0SEric Kohl ppResultRecords);
136630f34a0SEric Kohl if (Status == DNS_INFO_NO_RECORDS)
137630f34a0SEric Kohl {
138305035beSEric Kohl DPRINT("DNS query!\n");
139305035beSEric Kohl Status = Query_Main(pszName,
140305035beSEric Kohl wType,
141305035beSEric Kohl dwFlags,
142305035beSEric Kohl ppResultRecords);
143d49d7b32SEric Kohl if (Status == ERROR_SUCCESS)
144d49d7b32SEric Kohl {
145305035beSEric Kohl DPRINT("DNS query successful!\n");
14617f932d7SEric Kohl DnsIntCacheAddEntry(*ppResultRecords, FALSE);
147d49d7b32SEric Kohl }
148d49d7b32SEric Kohl }
149630f34a0SEric Kohl }
150d49d7b32SEric Kohl
151d49d7b32SEric Kohl if (dwRecords)
152305035beSEric Kohl {
153d49d7b32SEric Kohl *dwRecords = 0;
154d49d7b32SEric Kohl
155d49d7b32SEric Kohl if (Status == ERROR_SUCCESS)
156d49d7b32SEric Kohl {
157d49d7b32SEric Kohl Record = *ppResultRecords;
158d49d7b32SEric Kohl while (Record)
159d49d7b32SEric Kohl {
160305035beSEric Kohl DPRINT("Record: %S\n", Record->pName);
161d49d7b32SEric Kohl (*dwRecords)++;
162d49d7b32SEric Kohl Record = Record->pNext;
163d49d7b32SEric Kohl }
164d49d7b32SEric Kohl }
165305035beSEric Kohl }
166d49d7b32SEric Kohl
167305035beSEric Kohl DPRINT("R_ResolverQuery result %ld %ld\n", Status, *dwRecords);
168d49d7b32SEric Kohl
169d49d7b32SEric Kohl return Status;
170d49d7b32SEric Kohl }
171d49d7b32SEric Kohl
midl_user_allocate(SIZE_T len)172d49d7b32SEric Kohl void __RPC_FAR * __RPC_USER midl_user_allocate(SIZE_T len)
173d49d7b32SEric Kohl {
174d49d7b32SEric Kohl return HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, len);
175d49d7b32SEric Kohl }
176d49d7b32SEric Kohl
midl_user_free(void __RPC_FAR * ptr)177d49d7b32SEric Kohl void __RPC_USER midl_user_free(void __RPC_FAR * ptr)
178d49d7b32SEric Kohl {
179d49d7b32SEric Kohl HeapFree(GetProcessHeap(), 0, ptr);
180d49d7b32SEric Kohl }
181d49d7b32SEric Kohl
DNSRSLVR_RPC_HANDLE_rundown(DNSRSLVR_HANDLE hClientHandle)182630f34a0SEric Kohl void __RPC_USER DNSRSLVR_RPC_HANDLE_rundown(DNSRSLVR_HANDLE hClientHandle)
183d49d7b32SEric Kohl {
184d49d7b32SEric Kohl }
185