2019-10-27 12:45:52 +00:00
|
|
|
/*
|
|
|
|
* PROJECT: ReactOS DNS Resolver
|
|
|
|
* LICENSE: GPL - See COPYING in the top level directory
|
|
|
|
* FILE: base/services/dnsrslvr/rpcserver.c
|
|
|
|
* PURPOSE: RPC server interface
|
|
|
|
* COPYRIGHT: Copyright 2016 Christoph von Wittich
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "precomp.h"
|
|
|
|
|
|
|
|
#define NDEBUG
|
|
|
|
#include <debug.h>
|
|
|
|
|
|
|
|
DWORD
|
|
|
|
WINAPI
|
|
|
|
RpcThreadRoutine(LPVOID lpParameter)
|
|
|
|
{
|
|
|
|
RPC_STATUS Status;
|
|
|
|
|
|
|
|
Status = RpcServerUseProtseqEpW(L"ncalrpc", 20, L"DNSResolver", NULL);
|
|
|
|
if (Status != RPC_S_OK)
|
|
|
|
{
|
|
|
|
DPRINT("RpcServerUseProtseqEpW() failed (Status %lx)\n", Status);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
Status = RpcServerRegisterIf(DnsResolver_v2_0_s_ifspec, NULL, NULL);
|
|
|
|
if (Status != RPC_S_OK)
|
|
|
|
{
|
|
|
|
DPRINT("RpcServerRegisterIf() failed (Status %lx)\n", Status);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
Status = RpcServerListen(1, RPC_C_LISTEN_MAX_CALLS_DEFAULT, 0);
|
|
|
|
if (Status != RPC_S_OK)
|
|
|
|
{
|
|
|
|
DPRINT("RpcServerListen() failed (Status %lx)\n", Status);
|
|
|
|
}
|
|
|
|
|
|
|
|
DPRINT("RpcServerListen finished\n");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
DWORD
|
|
|
|
R_ResolverFlushCache(
|
|
|
|
DNSRSLVR_HANDLE pwszServerName)
|
|
|
|
{
|
2019-11-10 14:28:42 +00:00
|
|
|
DPRINT("R_ResolverFlushCache()\n");
|
|
|
|
|
2019-10-27 12:45:52 +00:00
|
|
|
// FIXME Should store (and flush) entries by server handle
|
|
|
|
DnsIntCacheFlush();
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
DWORD
|
|
|
|
R_ResolverQuery(
|
2019-11-10 14:28:42 +00:00
|
|
|
DNSRSLVR_HANDLE pszServerName,
|
|
|
|
LPCWSTR pszName,
|
2019-10-27 12:45:52 +00:00
|
|
|
WORD wType,
|
2019-11-10 14:28:42 +00:00
|
|
|
DWORD dwFlags,
|
2019-10-27 12:45:52 +00:00
|
|
|
DWORD *dwRecords,
|
|
|
|
DNS_RECORDW **ppResultRecords)
|
|
|
|
{
|
2019-11-10 14:28:42 +00:00
|
|
|
PDNS_RECORDW Record;
|
|
|
|
DNS_STATUS Status;
|
|
|
|
|
|
|
|
DPRINT("R_ResolverQuery(%S %S %x %lx %p %p)\n",
|
|
|
|
pszServerName, pszName, wType, dwFlags, dwRecords, ppResultRecords);
|
2019-10-27 12:45:52 +00:00
|
|
|
|
2019-11-10 14:28:42 +00:00
|
|
|
if (pszName == NULL || wType == 0 || ppResultRecords == NULL)
|
|
|
|
return ERROR_INVALID_PARAMETER;
|
2019-10-27 12:45:52 +00:00
|
|
|
|
2019-11-10 14:28:42 +00:00
|
|
|
if ((dwFlags & DNS_QUERY_WIRE_ONLY) != 0 && (dwFlags & DNS_QUERY_NO_WIRE_QUERY) != 0)
|
2019-10-27 12:45:52 +00:00
|
|
|
return ERROR_INVALID_PARAMETER;
|
|
|
|
|
2019-11-10 14:28:42 +00:00
|
|
|
if (DnsIntCacheGetEntryFromName(pszName, ppResultRecords))
|
2019-10-27 12:45:52 +00:00
|
|
|
{
|
2019-11-10 14:28:42 +00:00
|
|
|
DPRINT("DNS cache query successful!\n");
|
2019-10-27 12:45:52 +00:00
|
|
|
Status = ERROR_SUCCESS;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-11-10 14:28:42 +00:00
|
|
|
DPRINT("DNS query!\n");
|
|
|
|
Status = Query_Main(pszName,
|
|
|
|
wType,
|
|
|
|
dwFlags,
|
|
|
|
ppResultRecords);
|
2019-10-27 12:45:52 +00:00
|
|
|
if (Status == ERROR_SUCCESS)
|
|
|
|
{
|
2019-11-10 14:28:42 +00:00
|
|
|
DPRINT("DNS query successful!\n");
|
|
|
|
DnsIntCacheAddEntry(*ppResultRecords);
|
2019-10-27 12:45:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (dwRecords)
|
2019-11-10 14:28:42 +00:00
|
|
|
{
|
2019-10-27 12:45:52 +00:00
|
|
|
*dwRecords = 0;
|
|
|
|
|
2019-11-10 14:28:42 +00:00
|
|
|
if (Status == ERROR_SUCCESS)
|
2019-10-27 12:45:52 +00:00
|
|
|
{
|
2019-11-10 14:28:42 +00:00
|
|
|
Record = *ppResultRecords;
|
|
|
|
while (Record)
|
|
|
|
{
|
|
|
|
DPRINT("Record: %S\n", Record->pName);
|
2019-10-27 12:45:52 +00:00
|
|
|
(*dwRecords)++;
|
2019-11-10 14:28:42 +00:00
|
|
|
Record = Record->pNext;
|
|
|
|
}
|
2019-10-27 12:45:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-11-10 14:28:42 +00:00
|
|
|
DPRINT("R_ResolverQuery result %ld %ld\n", Status, *dwRecords);
|
2019-10-27 12:45:52 +00:00
|
|
|
|
|
|
|
return 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);
|
|
|
|
}
|
|
|
|
|
|
|
|
void __RPC_USER WLANSVC_RPC_HANDLE_rundown(DNSRSLVR_HANDLE hClientHandle)
|
|
|
|
{
|
|
|
|
}
|