ReactOS  0.4.14-dev-384-g5b37caa
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)
 
DNS_STATUS 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 1104 of file query.c.

1105 {
1106  DNS_STATUS Status = ERROR_SUCCESS;
1107 
1108  DPRINT("DnsFlushResolverCache()\n");
1109 
1110  RpcTryExcept
1111  {
1113  DPRINT("R_ResolverFlushCache() returned %lu\n", Status);
1114  }
1116  {
1118  DPRINT("Exception returned %lu\n", Status);
1119  }
1120  RpcEndExcept;
1121 
1122  return (Status == ERROR_SUCCESS);
1123 }
#define RpcEndExcept
Definition: rpc.h:128
#define ERROR_SUCCESS
Definition: deptool.c:10
DWORD __stdcall R_ResolverFlushCache(DNSRSLVR_HANDLE pwszServerName)
Definition: rpcserver.c:46
#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 271 of file stubs.c.

273 {
275  return TRUE;
276 }
#define TRUE
Definition: types.h:120
#define UNIMPLEMENTED
Definition: stubs.c:20

Referenced by DisplayDns().

◆ GetCurrentTimeInSeconds()

DNS_STATUS WINAPI GetCurrentTimeInSeconds ( VOID  )

Definition at line 1127 of file query.c.

1128 {
1129  FILETIME Time;
1131  ULARGE_INTEGER lTime, lAdj;
1132  SYSTEMTIME st = {1970, 1, 0, 1, 0, 0, 0};
1133 
1135  memcpy(&lAdj, &Adjustment, sizeof(lAdj));
1137  memcpy(&lTime, &Time, sizeof(lTime));
1138  lTime.QuadPart -= lAdj.QuadPart;
1139  return (DWORD)(lTime.QuadPart/10000000ULL);
1140 }
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:451
#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:148
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 763 of file query.c.

767 {
768  adns_state astate;
769  int quflags = (Options & DNS_QUERY_NO_RECURSION) == 0 ? adns_qf_search : 0;
770  int adns_error;
771  adns_answer *answer;
772  LPSTR CurrentName;
773  unsigned i, CNameLoop;
774  PFIXED_INFO network_info;
775  ULONG network_info_blen = 0;
776  DWORD network_info_result;
777  PIP_ADDR_STRING pip;
779  struct in_addr addr;
780  PCHAR HostWithDomainName;
781  PCHAR AnsiName;
782  size_t NameLen = 0;
783 
784  if (Name == NULL)
786  if (QueryResultSet == NULL)
788 
789  *QueryResultSet = NULL;
790 
791  switch (Type)
792  {
793  case DNS_TYPE_A:
794  /* FIXME: how much instead of MAX_PATH? */
795  NameLen = WideCharToMultiByte(CP_ACP,
796  0,
797  Name,
798  -1,
799  NULL,
800  0,
801  NULL,
802  0);
803  AnsiName = RtlAllocateHeap(RtlGetProcessHeap(), 0, NameLen);
804  if (NULL == AnsiName)
805  {
806  return ERROR_OUTOFMEMORY;
807  }
809  0,
810  Name,
811  -1,
812  AnsiName,
813  NameLen,
814  NULL,
815  0);
816  NameLen--;
817  /* Is it an IPv4 address? */
818  if (ParseV4Address(AnsiName, &Address))
819  {
820  RtlFreeHeap(RtlGetProcessHeap(), 0, AnsiName);
821  *QueryResultSet = (PDNS_RECORD)RtlAllocateHeap(RtlGetProcessHeap(), 0, sizeof(DNS_RECORD));
822 
823  if (NULL == *QueryResultSet)
824  {
825  return ERROR_OUTOFMEMORY;
826  }
827 
828  (*QueryResultSet)->pNext = NULL;
829  (*QueryResultSet)->wType = Type;
830  (*QueryResultSet)->wDataLength = sizeof(DNS_A_DATA);
831  (*QueryResultSet)->Data.A.IpAddress = Address;
832 
833  (*QueryResultSet)->pName = (LPSTR)xstrsave(Name);
834 
835  return (*QueryResultSet)->pName ? ERROR_SUCCESS : ERROR_OUTOFMEMORY;
836  }
837 
838  /* Check allowed characters
839  * According to RFC a-z,A-Z,0-9,-,_, but can't start or end with - or _
840  */
841  if (AnsiName[0] == '-' || AnsiName[0] == '_' || AnsiName[NameLen - 1] == '-' ||
842  AnsiName[NameLen - 1] == '_' || strstr(AnsiName, "..") != NULL)
843  {
844  RtlFreeHeap(RtlGetProcessHeap(), 0, AnsiName);
845  return ERROR_INVALID_NAME;
846  }
847  i = 0;
848  while (i < NameLen)
849  {
850  if (!((AnsiName[i] >= 'a' && AnsiName[i] <= 'z') ||
851  (AnsiName[i] >= 'A' && AnsiName[i] <= 'Z') ||
852  (AnsiName[i] >= '0' && AnsiName[i] <= '9') ||
853  AnsiName[i] == '-' || AnsiName[i] == '_' || AnsiName[i] == '.'))
854  {
855  RtlFreeHeap(RtlGetProcessHeap(), 0, AnsiName);
857  }
858  i++;
859  }
860 
861  if ((Options & DNS_QUERY_NO_HOSTS_FILE) == 0)
862  {
863  if ((Address = FindEntryInHosts(AnsiName)) != 0)
864  {
865  RtlFreeHeap(RtlGetProcessHeap(), 0, AnsiName);
866  *QueryResultSet = (PDNS_RECORD)RtlAllocateHeap(RtlGetProcessHeap(), 0, sizeof(DNS_RECORD));
867 
868  if (NULL == *QueryResultSet)
869  {
870  return ERROR_OUTOFMEMORY;
871  }
872 
873  (*QueryResultSet)->pNext = NULL;
874  (*QueryResultSet)->wType = Type;
875  (*QueryResultSet)->wDataLength = sizeof(DNS_A_DATA);
876  (*QueryResultSet)->Data.A.IpAddress = Address;
877 
878  (*QueryResultSet)->pName = (LPSTR)xstrsave(Name);
879 
880  return (*QueryResultSet)->pName ? ERROR_SUCCESS : ERROR_OUTOFMEMORY;
881  }
882  }
883 
884  network_info_result = GetNetworkParams(NULL, &network_info_blen);
885  network_info = (PFIXED_INFO)RtlAllocateHeap(RtlGetProcessHeap(), 0, (size_t)network_info_blen);
886  if (NULL == network_info)
887  {
888  return ERROR_OUTOFMEMORY;
889  }
890 
891  network_info_result = GetNetworkParams(network_info, &network_info_blen);
892  if (network_info_result != ERROR_SUCCESS)
893  {
894  RtlFreeHeap(RtlGetProcessHeap(), 0, network_info);
895  return network_info_result;
896  }
897 
898  if ((Address = CheckForCurrentHostname(NameLen != 0 ? AnsiName : network_info->HostName, network_info)) != 0)
899  {
900  size_t TempLen = 2, StringLength = 0;
901  RtlFreeHeap(RtlGetProcessHeap(), 0, AnsiName);
902  StringCchLengthA(network_info->HostName, sizeof(network_info->HostName), &StringLength);
903  TempLen += StringLength;
904  StringCchLengthA(network_info->DomainName, sizeof(network_info->DomainName), &StringLength);
905  TempLen += StringLength;
906  HostWithDomainName = (PCHAR)RtlAllocateHeap(RtlGetProcessHeap(), 0, TempLen);
907  StringCchCopyA(HostWithDomainName, TempLen, network_info->HostName);
908  if (network_info->DomainName[0])
909  {
910  StringCchCatA(HostWithDomainName, TempLen, ".");
911  StringCchCatA(HostWithDomainName, TempLen, network_info->DomainName);
912  }
913  RtlFreeHeap(RtlGetProcessHeap(), 0, network_info);
914  *QueryResultSet = (PDNS_RECORD)RtlAllocateHeap(RtlGetProcessHeap(), 0, sizeof(DNS_RECORD));
915 
916  if (NULL == *QueryResultSet)
917  {
918  RtlFreeHeap(RtlGetProcessHeap(), 0, HostWithDomainName);
919  return ERROR_OUTOFMEMORY;
920  }
921 
922  (*QueryResultSet)->pNext = NULL;
923  (*QueryResultSet)->wType = Type;
924  (*QueryResultSet)->wDataLength = sizeof(DNS_A_DATA);
925  (*QueryResultSet)->Data.A.IpAddress = Address;
926 
927  (*QueryResultSet)->pName = (LPSTR)DnsCToW(HostWithDomainName);
928 
929  RtlFreeHeap(RtlGetProcessHeap(), 0, HostWithDomainName);
930  return (*QueryResultSet)->pName ? ERROR_SUCCESS : ERROR_OUTOFMEMORY;
931  }
932 
933  if ((Options & DNS_QUERY_NO_WIRE_QUERY) != 0)
934  {
935  RtlFreeHeap(RtlGetProcessHeap(), 0, AnsiName);
936  RtlFreeHeap(RtlGetProcessHeap(), 0, network_info);
937  return ERROR_FILE_NOT_FOUND;
938  }
939 
940  adns_error = adns_init(&astate, adns_if_noenv | adns_if_noerrprint | adns_if_noserverwarn, 0);
941  if (adns_error != adns_s_ok)
942  {
943  RtlFreeHeap(RtlGetProcessHeap(), 0, AnsiName);
944  RtlFreeHeap(RtlGetProcessHeap(), 0, network_info);
945  return DnsIntTranslateAdnsToDNS_STATUS(adns_error);
946  }
947  for (pip = &(network_info->DnsServerList); pip; pip = pip->Next)
948  {
949  addr.s_addr = inet_addr(pip->IpAddress.String);
950  if ((addr.s_addr != INADDR_ANY) && (addr.s_addr != INADDR_NONE))
951  adns_addserver(astate, addr);
952  }
953  if (network_info->DomainName[0])
954  {
955  adns_ccf_search(astate, "LOCALDOMAIN", -1, network_info->DomainName);
956  }
957  RtlFreeHeap(RtlGetProcessHeap(), 0, network_info);
958 
959  if (!adns_numservers(astate))
960  {
961  /* There are no servers to query so bail out */
962  adns_finish(astate);
963  RtlFreeHeap(RtlGetProcessHeap(), 0, AnsiName);
964  return ERROR_FILE_NOT_FOUND;
965  }
966 
967  /*
968  * adns doesn't resolve chained CNAME records (a CNAME which points to
969  * another CNAME pointing to another... pointing to an A record), according
970  * to a mailing list thread the authors believe that chained CNAME records
971  * are invalid and the DNS entries should be fixed. That's a nice academic
972  * standpoint, but there certainly are chained CNAME records out there,
973  * even some fairly major ones (at the time of this writing
974  * download.mozilla.org is a chained CNAME). Everyone else seems to resolve
975  * these fine, so we should too. So we loop here to try to resolve CNAME
976  * chains ourselves. Of course, there must be a limit to protect against
977  * CNAME loops.
978  */
979 
980 #define CNAME_LOOP_MAX 16
981 
982  CurrentName = AnsiName;
983 
984  for (CNameLoop = 0; CNameLoop < CNAME_LOOP_MAX; CNameLoop++)
985  {
986  adns_error = adns_synchronous(astate, CurrentName, adns_r_addr, quflags, &answer);
987 
988  if (adns_error != adns_s_ok)
989  {
990  adns_finish(astate);
991 
992  if (CurrentName != AnsiName)
993  RtlFreeHeap(RtlGetProcessHeap(), 0, CurrentName);
994 
995  RtlFreeHeap(RtlGetProcessHeap(), 0, AnsiName);
996  return DnsIntTranslateAdnsToDNS_STATUS(adns_error);
997  }
998 
999  if (answer && answer->rrs.addr)
1000  {
1001  if (CurrentName != AnsiName)
1002  RtlFreeHeap(RtlGetProcessHeap(), 0, CurrentName);
1003 
1004  RtlFreeHeap(RtlGetProcessHeap(), 0, AnsiName);
1005  *QueryResultSet = (PDNS_RECORD)RtlAllocateHeap(RtlGetProcessHeap(), 0, sizeof(DNS_RECORD));
1006 
1007  if (NULL == *QueryResultSet)
1008  {
1009  adns_finish(astate);
1010  return ERROR_OUTOFMEMORY;
1011  }
1012 
1013  (*QueryResultSet)->pNext = NULL;
1014  (*QueryResultSet)->wType = Type;
1015  (*QueryResultSet)->wDataLength = sizeof(DNS_A_DATA);
1016  (*QueryResultSet)->Data.A.IpAddress = answer->rrs.addr->addr.inet.sin_addr.s_addr;
1017 
1018  adns_finish(astate);
1019 
1020  (*QueryResultSet)->pName = (LPSTR)xstrsave(Name);
1021 
1022  return (*QueryResultSet)->pName ? ERROR_SUCCESS : ERROR_OUTOFMEMORY;
1023  }
1024 
1025  if (NULL == answer || adns_s_prohibitedcname != answer->status || NULL == answer->cname)
1026  {
1027  adns_finish(astate);
1028 
1029  if (CurrentName != AnsiName)
1030  RtlFreeHeap(RtlGetProcessHeap(), 0, CurrentName);
1031 
1032  RtlFreeHeap(RtlGetProcessHeap(), 0, AnsiName);
1033  return ERROR_FILE_NOT_FOUND;
1034  }
1035 
1036  if (CurrentName != AnsiName)
1037  RtlFreeHeap(RtlGetProcessHeap(), 0, CurrentName);
1038 
1039  CurrentName = (LPSTR)xstrsaveA(answer->cname);
1040 
1041  if (!CurrentName)
1042  {
1043  RtlFreeHeap(RtlGetProcessHeap(), 0, AnsiName);
1044  adns_finish(astate);
1045  return ERROR_OUTOFMEMORY;
1046  }
1047  }
1048 
1049  adns_finish(astate);
1050  RtlFreeHeap(RtlGetProcessHeap(), 0, AnsiName);
1051  RtlFreeHeap(RtlGetProcessHeap(), 0, CurrentName);
1052  return ERROR_FILE_NOT_FOUND;
1053 
1054  default:
1055  return ERROR_OUTOFMEMORY; /* XXX arty: find a better error code. */
1056  }
1057 }
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
char * strstr(char *String1, char *String2)
Definition: utclib.c:653
#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
union adns_answer::@3854 rrs
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:70
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
IP4_ADDRESS FindEntryInHosts(CONST CHAR *name)
Definition: query.c:614
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
DWORD IP4_ADDRESS
Definition: windns.h:36
BOOL ParseV4Address(LPCSTR AddressString, OUT PDWORD pAddress)
Definition: query.c:544
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:345
#define ERROR_FILE_NOT_FOUND
Definition: disk.h:79
IP4_ADDRESS CheckForCurrentHostname(CONST CHAR *Name, PFIXED_INFO network_info)
Definition: query.c:474
#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
union adns_rr_addr::@3853 addr
CHAR * xstrsaveA(const CHAR *str)
Definition: query.c:363
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
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
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
#define DNS_QUERY_NO_HOSTS_FILE
Definition: windns.h:15
struct sockaddr_in inet
Definition: adns.h:271
#define DNS_QUERY_NO_WIRE_QUERY
Definition: windns.h:13
#define DNS_ERROR_INVALID_NAME_CHAR
Definition: winerror.h:1877
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
#define ERROR_INVALID_NAME
Definition: compat.h:93
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().