ReactOS  0.4.15-dev-448-gd6c4411
windns_undoc.h File Reference
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  _DNS_CACHE_ENTRY
 

Typedefs

typedef struct _DNS_CACHE_ENTRY DNS_CACHE_ENTRY
 
typedef struct _DNS_CACHE_ENTRYPDNS_CACHE_ENTRY
 

Functions

BOOL WINAPI DnsFlushResolverCache (VOID)
 
BOOL WINAPI DnsGetCacheDataTable (_Out_ PDNS_CACHE_ENTRY *DnsCache)
 
DWORD WINAPI GetCurrentTimeInSeconds (VOID)
 
DNS_STATUS WINAPI Query_Main (LPCWSTR Name, WORD Type, DWORD Options, PDNS_RECORD *QueryResultSet)
 

Typedef Documentation

◆ DNS_CACHE_ENTRY

◆ PDNS_CACHE_ENTRY

Function Documentation

◆ DnsFlushResolverCache()

BOOL WINAPI DnsFlushResolverCache ( VOID  )

Definition at line 933 of file query.c.

934 {
935  DNS_STATUS Status = ERROR_SUCCESS;
936 
937  DPRINT("DnsFlushResolverCache()\n");
938 
940  {
942  DPRINT("R_ResolverFlushCache() returned %lu\n", Status);
943  }
945  {
947  DPRINT("Exception returned %lu\n", Status);
948  }
949  RpcEndExcept;
950 
951  return (Status == ERROR_SUCCESS);
952 }
#define RpcEndExcept
Definition: rpc.h:128
#define ERROR_SUCCESS
Definition: deptool.c:10
DWORD __stdcall R_ResolverFlushCache(_In_ DNSRSLVR_HANDLE pwszServerName)
Definition: rpcserver.c:62
#define RpcTryExcept
Definition: rpc.h:126
#define EXCEPTION_EXECUTE_HANDLER
Definition: excpt.h:85
smooth NULL
Definition: ftsmooth.c:416
void DPRINT(...)
Definition: polytest.cpp:61
#define RpcExceptionCode()
Definition: rpc.h:132
Status
Definition: gdiplustypes.h:24
#define RpcExcept(expr)
Definition: rpc.h:127

Referenced by FlushDns().

◆ DnsGetCacheDataTable()

BOOL WINAPI DnsGetCacheDataTable ( _Out_ PDNS_CACHE_ENTRY DnsCache)

Definition at line 956 of file query.c.

958 {
959  DNS_STATUS Status = ERROR_SUCCESS;
960  PDNS_CACHE_ENTRY CacheEntries = NULL;
961 
962  if (DnsCache == NULL)
963  return FALSE;
964 
966  {
968  &CacheEntries);
969  DPRINT("CRrReadCache() returned %lu\n", Status);
970  }
972  {
974  DPRINT1("Exception returned %lu\n", Status);
975  }
976  RpcEndExcept;
977 
978  if (Status != ERROR_SUCCESS)
979  return FALSE;
980 
981  if (CacheEntries == NULL)
982  return FALSE;
983 
984  *DnsCache = CacheEntries;
985 
986  return TRUE;
987 }
#define RpcEndExcept
Definition: rpc.h:128
#define TRUE
Definition: types.h:120
#define ERROR_SUCCESS
Definition: deptool.c:10
#define RpcTryExcept
Definition: rpc.h:126
#define EXCEPTION_EXECUTE_HANDLER
Definition: excpt.h:85
Definition: windns_undoc.h:8
smooth NULL
Definition: ftsmooth.c:416
DWORD __stdcall CRrReadCache(_In_ DNSRSLVR_HANDLE pwszServerName, _Out_ DNS_CACHE_ENTRY **ppCacheEntries)
Definition: rpcserver.c:48
void DPRINT(...)
Definition: polytest.cpp:61
#define RpcExceptionCode()
Definition: rpc.h:132
static RESOLVER_CACHE DnsCache
Definition: cache.c:14
Status
Definition: gdiplustypes.h:24
#define DPRINT1
Definition: precomp.h:8
#define RpcExcept(expr)
Definition: rpc.h:127

Referenced by DisplayDns().

◆ GetCurrentTimeInSeconds()

DWORD WINAPI GetCurrentTimeInSeconds ( VOID  )

Definition at line 991 of file query.c.

992 {
993  FILETIME Time;
995  ULARGE_INTEGER lTime, lAdj;
996  SYSTEMTIME st = {1970, 1, 0, 1, 0, 0, 0};
997 
999  memcpy(&lAdj, &Adjustment, sizeof(lAdj));
1001  memcpy(&lTime, &Time, sizeof(lTime));
1002  lTime.QuadPart -= lAdj.QuadPart;
1003  return (DWORD)(lTime.QuadPart/10000000ULL);
1004 }
VOID WINAPI GetSystemTimeAsFileTime(OUT PFILETIME lpFileTime)
Definition: time.c:128
ULONGLONG QuadPart
Definition: ms-dtyp.idl:185
_In_ KPRIORITY _In_ LONG Adjustment
Definition: kefuncs.h:438
#define ULL(a, b)
Definition: format_msg.c:27
unsigned long DWORD
Definition: ntddk_ex.h:95
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
BOOL WINAPI SystemTimeToFileTime(IN CONST SYSTEMTIME *lpSystemTime, OUT LPFILETIME lpFileTime)
Definition: time.c:158
static PLARGE_INTEGER Time
Definition: time.c:105

Referenced by WSPAccept(), WSPConnect(), and WSPGetSockOpt().

◆ Query_Main()

DNS_STATUS WINAPI Query_Main ( LPCWSTR  Name,
WORD  Type,
DWORD  Options,
PDNS_RECORD QueryResultSet 
)

Definition at line 654 of file query.c.

658 {
659  adns_state astate;
660  int quflags = (Options & DNS_QUERY_NO_RECURSION) == 0 ? adns_qf_search : 0;
661  int adns_error;
662  adns_answer *answer;
663  LPSTR CurrentName;
664  unsigned CNameLoop;
665  PFIXED_INFO network_info;
666  ULONG network_info_blen = 0;
667  DWORD network_info_result;
668  PIP_ADDR_STRING pip;
670  struct in_addr addr;
671  PCHAR HostWithDomainName;
672  PCHAR AnsiName;
673  size_t NameLen = 0;
674 
675  if (Name == NULL)
677  if (QueryResultSet == NULL)
679 
680  *QueryResultSet = NULL;
681 
682  switch (Type)
683  {
684  case DNS_TYPE_A:
685  /* FIXME: how much instead of MAX_PATH? */
686  NameLen = WideCharToMultiByte(CP_ACP,
687  0,
688  Name,
689  -1,
690  NULL,
691  0,
692  NULL,
693  0);
694  AnsiName = RtlAllocateHeap(RtlGetProcessHeap(), 0, NameLen);
695  if (NULL == AnsiName)
696  {
697  return ERROR_OUTOFMEMORY;
698  }
700  0,
701  Name,
702  -1,
703  AnsiName,
704  NameLen,
705  NULL,
706  0);
707  NameLen--;
708 
709  network_info_result = GetNetworkParams(NULL, &network_info_blen);
710  network_info = (PFIXED_INFO)RtlAllocateHeap(RtlGetProcessHeap(), 0, (size_t)network_info_blen);
711  if (NULL == network_info)
712  {
713  return ERROR_OUTOFMEMORY;
714  }
715 
716  network_info_result = GetNetworkParams(network_info, &network_info_blen);
717  if (network_info_result != ERROR_SUCCESS)
718  {
719  RtlFreeHeap(RtlGetProcessHeap(), 0, network_info);
720  return network_info_result;
721  }
722 
723  if ((Address = CheckForCurrentHostname(NameLen != 0 ? AnsiName : network_info->HostName, network_info)) != 0)
724  {
725  size_t TempLen = 2, StringLength = 0;
726  RtlFreeHeap(RtlGetProcessHeap(), 0, AnsiName);
727  StringCchLengthA(network_info->HostName, sizeof(network_info->HostName), &StringLength);
728  TempLen += StringLength;
729  StringCchLengthA(network_info->DomainName, sizeof(network_info->DomainName), &StringLength);
730  TempLen += StringLength;
731  HostWithDomainName = (PCHAR)RtlAllocateHeap(RtlGetProcessHeap(), 0, TempLen);
732  StringCchCopyA(HostWithDomainName, TempLen, network_info->HostName);
733  if (network_info->DomainName[0])
734  {
735  StringCchCatA(HostWithDomainName, TempLen, ".");
736  StringCchCatA(HostWithDomainName, TempLen, network_info->DomainName);
737  }
738  RtlFreeHeap(RtlGetProcessHeap(), 0, network_info);
739  *QueryResultSet = (PDNS_RECORD)RtlAllocateHeap(RtlGetProcessHeap(), 0, sizeof(DNS_RECORD));
740 
741  if (NULL == *QueryResultSet)
742  {
743  RtlFreeHeap(RtlGetProcessHeap(), 0, HostWithDomainName);
744  return ERROR_OUTOFMEMORY;
745  }
746 
747  (*QueryResultSet)->pNext = NULL;
748  (*QueryResultSet)->wType = Type;
749  (*QueryResultSet)->wDataLength = sizeof(DNS_A_DATA);
750  (*QueryResultSet)->Flags.S.Section = DnsSectionAnswer;
751  (*QueryResultSet)->Flags.S.CharSet = DnsCharSetUnicode;
752  (*QueryResultSet)->Data.A.IpAddress = Address;
753 
754  (*QueryResultSet)->pName = (LPSTR)DnsCToW(HostWithDomainName);
755 
756  RtlFreeHeap(RtlGetProcessHeap(), 0, HostWithDomainName);
757  return (*QueryResultSet)->pName ? ERROR_SUCCESS : ERROR_OUTOFMEMORY;
758  }
759 
760  if ((Options & DNS_QUERY_NO_WIRE_QUERY) != 0)
761  {
762  RtlFreeHeap(RtlGetProcessHeap(), 0, AnsiName);
763  RtlFreeHeap(RtlGetProcessHeap(), 0, network_info);
764  return ERROR_FILE_NOT_FOUND;
765  }
766 
767  adns_error = adns_init(&astate, adns_if_noenv | adns_if_noerrprint | adns_if_noserverwarn, 0);
768  if (adns_error != adns_s_ok)
769  {
770  RtlFreeHeap(RtlGetProcessHeap(), 0, AnsiName);
771  RtlFreeHeap(RtlGetProcessHeap(), 0, network_info);
772  return DnsIntTranslateAdnsToDNS_STATUS(adns_error);
773  }
774  for (pip = &(network_info->DnsServerList); pip; pip = pip->Next)
775  {
776  addr.s_addr = inet_addr(pip->IpAddress.String);
777  if ((addr.s_addr != INADDR_ANY) && (addr.s_addr != INADDR_NONE))
778  adns_addserver(astate, addr);
779  }
780  if (network_info->DomainName[0])
781  {
782  adns_ccf_search(astate, "LOCALDOMAIN", -1, network_info->DomainName);
783  }
784  RtlFreeHeap(RtlGetProcessHeap(), 0, network_info);
785 
786  if (!adns_numservers(astate))
787  {
788  /* There are no servers to query so bail out */
789  adns_finish(astate);
790  RtlFreeHeap(RtlGetProcessHeap(), 0, AnsiName);
791  return ERROR_FILE_NOT_FOUND;
792  }
793 
794  /*
795  * adns doesn't resolve chained CNAME records (a CNAME which points to
796  * another CNAME pointing to another... pointing to an A record), according
797  * to a mailing list thread the authors believe that chained CNAME records
798  * are invalid and the DNS entries should be fixed. That's a nice academic
799  * standpoint, but there certainly are chained CNAME records out there,
800  * even some fairly major ones (at the time of this writing
801  * download.mozilla.org is a chained CNAME). Everyone else seems to resolve
802  * these fine, so we should too. So we loop here to try to resolve CNAME
803  * chains ourselves. Of course, there must be a limit to protect against
804  * CNAME loops.
805  */
806 
807 #define CNAME_LOOP_MAX 16
808 
809  CurrentName = AnsiName;
810 
811  for (CNameLoop = 0; CNameLoop < CNAME_LOOP_MAX; CNameLoop++)
812  {
813  adns_error = adns_synchronous(astate, CurrentName, adns_r_addr, quflags, &answer);
814 
815  if (adns_error != adns_s_ok)
816  {
817  adns_finish(astate);
818 
819  if (CurrentName != AnsiName)
820  RtlFreeHeap(RtlGetProcessHeap(), 0, CurrentName);
821 
822  RtlFreeHeap(RtlGetProcessHeap(), 0, AnsiName);
823  return DnsIntTranslateAdnsToDNS_STATUS(adns_error);
824  }
825 
826  if (answer && answer->rrs.addr)
827  {
828  if (CurrentName != AnsiName)
829  RtlFreeHeap(RtlGetProcessHeap(), 0, CurrentName);
830 
831  RtlFreeHeap(RtlGetProcessHeap(), 0, AnsiName);
832  *QueryResultSet = (PDNS_RECORD)RtlAllocateHeap(RtlGetProcessHeap(), 0, sizeof(DNS_RECORD));
833 
834  if (NULL == *QueryResultSet)
835  {
836  adns_finish(astate);
837  return ERROR_OUTOFMEMORY;
838  }
839 
840  (*QueryResultSet)->pNext = NULL;
841  (*QueryResultSet)->wType = Type;
842  (*QueryResultSet)->wDataLength = sizeof(DNS_A_DATA);
843  (*QueryResultSet)->Flags.S.Section = DnsSectionAnswer;
844  (*QueryResultSet)->Flags.S.CharSet = DnsCharSetUnicode;
845  (*QueryResultSet)->Data.A.IpAddress = answer->rrs.addr->addr.inet.sin_addr.s_addr;
846 
847  adns_finish(astate);
848 
849  (*QueryResultSet)->pName = (LPSTR)xstrsave(Name);
850 
851  return (*QueryResultSet)->pName ? ERROR_SUCCESS : ERROR_OUTOFMEMORY;
852  }
853 
854  if (NULL == answer || adns_s_prohibitedcname != answer->status || NULL == answer->cname)
855  {
856  adns_finish(astate);
857 
858  if (CurrentName != AnsiName)
859  RtlFreeHeap(RtlGetProcessHeap(), 0, CurrentName);
860 
861  RtlFreeHeap(RtlGetProcessHeap(), 0, AnsiName);
862  return ERROR_FILE_NOT_FOUND;
863  }
864 
865  if (CurrentName != AnsiName)
866  RtlFreeHeap(RtlGetProcessHeap(), 0, CurrentName);
867 
868  CurrentName = (LPSTR)xstrsaveA(answer->cname);
869 
870  if (!CurrentName)
871  {
872  RtlFreeHeap(RtlGetProcessHeap(), 0, AnsiName);
873  adns_finish(astate);
874  return ERROR_OUTOFMEMORY;
875  }
876  }
877 
878  adns_finish(astate);
879  RtlFreeHeap(RtlGetProcessHeap(), 0, AnsiName);
880  RtlFreeHeap(RtlGetProcessHeap(), 0, CurrentName);
881  return ERROR_FILE_NOT_FOUND;
882 
883  default:
884  return ERROR_OUTOFMEMORY; /* XXX arty: find a better error code. */
885  }
886 }
signed char * PCHAR
Definition: retypes.h:7
#define ERROR_INVALID_PARAMETER
Definition: compat.h:91
#define inet_addr(cp)
Definition: inet.h:98
Type
Definition: Type.h:6
#define ERROR_SUCCESS
Definition: deptool.c:10
#define WideCharToMultiByte
Definition: compat.h:101
#define DNS_TYPE_A
Definition: windns.h:41
ADNS_API void adns_finish(adns_state ads)
Definition: setup.c:650
#define CP_ACP
Definition: compat.h:99
IP_ADDRESS_STRING IpAddress
Definition: iptypes.h:47
struct _IP_ADDR_STRING * Next
Definition: iptypes.h:46
#define INADDR_NONE
Definition: tcp.c:42
BOOLEAN NTAPI RtlFreeHeap(IN PVOID HeapHandle, IN ULONG Flags, IN PVOID HeapBase)
Definition: heap.c:606
#define INADDR_ANY
Definition: StrAddr.c:4
char String[4 *4]
Definition: iptypes.h:42
adns_rr_addr * addr
Definition: adns.h:322
char * LPSTR
Definition: xmlstorage.h:182
enum OPTION_FLAGS Options
Definition: stats.c:44
static PWCHAR DnsCToW(const CHAR *NarrowString)
Definition: query.c:187
ADNS_API void adns_ccf_search(adns_state state, const char *fn, int lno, const char *buf)
Definition: setup.c:715
#define DNS_QUERY_NO_RECURSION
Definition: windns.h:11
DWORD IP4_ADDRESS
Definition: windns.h:36
STRSAFEAPI StringCchCatA(STRSAFE_LPSTR pszDest, size_t cchDest, STRSAFE_LPCSTR pszSrc)
Definition: strsafe.h:320
DWORD WINAPI GetNetworkParams(PFIXED_INFO pFixedInfo, PULONG pOutBufLen)
smooth NULL
Definition: ftsmooth.c:416
static WCHAR Address[46]
Definition: ping.c:68
char DomainName[MAX_DOMAIN_NAME_LEN+4]
Definition: iptypes.h:82
WCHAR * xstrsave(const WCHAR *str)
Definition: query.c:544
#define ERROR_FILE_NOT_FOUND
Definition: disk.h:79
IP4_ADDRESS CheckForCurrentHostname(CONST CHAR *Name, PFIXED_INFO network_info)
Definition: query.c:582
#define PCHAR
Definition: match.c:90
PVOID NTAPI RtlAllocateHeap(IN PVOID HeapHandle, IN ULONG Flags, IN SIZE_T Size)
Definition: heap.c:588
__kernel_size_t size_t
Definition: linux.h:237
CHAR * xstrsaveA(const CHAR *str)
Definition: query.c:562
ADNS_API int adns_numservers(adns_state state)
Definition: setup.c:718
Definition: tcpip.h:125
DNS_STATUS DnsIntTranslateAdnsToDNS_STATUS(int Status)
Definition: adns.c:17
unsigned long DWORD
Definition: ntddk_ex.h:95
#define CNAME_LOOP_MAX
union adns_rr_addr::@3889 addr
ADNS_API void adns_addserver(adns_state state, struct in_addr server)
Definition: setup.c:712
adns_status status
Definition: adns.h:311
GLenum const GLvoid * addr
Definition: glext.h:9621
char * cname
Definition: adns.h:312
char HostName[MAX_HOSTNAME_LEN+4]
Definition: iptypes.h:81
struct FIXED_INFO * PFIXED_INFO
#define DNS_RECORD
Definition: windns.h:635
union adns_answer::@3890 rrs
STRSAFEAPI StringCchCopyA(STRSAFE_LPSTR pszDest, size_t cchDest, STRSAFE_LPCSTR pszSrc)
Definition: strsafe.h:145
STRSAFEAPI StringCchLengthA(STRSAFE_LPCSTR psz, size_t cchMax, size_t *pcchLength)
Definition: strsafe.h:832
ADNS_API int adns_init(adns_state *newstate_r, adns_initflags flags, FILE *diagfile)
Definition: setup.c:568
struct sockaddr_in inet
Definition: adns.h:271
#define DNS_QUERY_NO_WIRE_QUERY
Definition: windns.h:13
int adns_synchronous(adns_state ads, const char *owner, adns_rrtype type, adns_queryflags flags, adns_answer **answer_r)
Definition: query.c:314
unsigned int ULONG
Definition: retypes.h:1
IP_ADDR_STRING DnsServerList
Definition: iptypes.h:84
#define PDNS_RECORD
Definition: windns.h:636
#define ERROR_OUTOFMEMORY
Definition: deptool.c:13

Referenced by R_ResolverQuery().