Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

189 lines
2.8 KiB

  1. /*++
  2. Copyright (c) 1996-2002 Microsoft Corporation
  3. Module Name:
  4. dnsapi.c
  5. Abstract:
  6. Domain Name System (DNS) API
  7. Random DNS API routines.
  8. Author:
  9. GlennC 22-Jan-1997
  10. Revision History:
  11. Jim Gilroy (jamesg) March 2000 cleanup
  12. Jim Gilroy (jamesg) May 2002 security\robustness fixups
  13. --*/
  14. #include "local.h"
  15. #include <lmcons.h>
  16. #define DNS_NET_FAILURE_CACHE_TIME 30 // Seconds
  17. //
  18. // Globals
  19. //
  20. DWORD g_NetFailureTime;
  21. DNS_STATUS g_NetFailureStatus;
  22. IP4_ADDRESS g_LastDNSServerUpdated = 0;
  23. //
  24. // Net failure caching
  25. //
  26. BOOL
  27. IsKnownNetFailure(
  28. VOID
  29. )
  30. /*++
  31. Routine Description:
  32. None.
  33. Arguments:
  34. None.
  35. Return Value:
  36. None.
  37. --*/
  38. {
  39. BOOL flag = FALSE;
  40. DNSDBG( TRACE, ( "IsKnownNetFailure()\n" ));
  41. LOCK_GENERAL();
  42. if ( g_NetFailureStatus )
  43. {
  44. if ( g_NetFailureTime < Dns_GetCurrentTimeInSeconds() )
  45. {
  46. g_NetFailureTime = 0;
  47. g_NetFailureStatus = ERROR_SUCCESS;
  48. flag = FALSE;
  49. }
  50. else
  51. {
  52. SetLastError( g_NetFailureStatus );
  53. flag = TRUE;
  54. }
  55. }
  56. UNLOCK_GENERAL();
  57. return flag;
  58. }
  59. VOID
  60. SetKnownNetFailure(
  61. IN DNS_STATUS Status
  62. )
  63. /*++
  64. Routine Description:
  65. None.
  66. Arguments:
  67. None.
  68. Return Value:
  69. None.
  70. --*/
  71. {
  72. DNSDBG( TRACE, ( "SetKnownNetFailure()\n" ));
  73. LOCK_GENERAL();
  74. g_NetFailureTime = Dns_GetCurrentTimeInSeconds() +
  75. DNS_NET_FAILURE_CACHE_TIME;
  76. g_NetFailureStatus = Status;
  77. UNLOCK_GENERAL();
  78. }
  79. BOOL
  80. WINAPI
  81. DnsGetCacheDataTable(
  82. OUT PDNS_CACHE_TABLE * ppTable
  83. )
  84. /*++
  85. Routine Description:
  86. Get cache data table.
  87. Arguments:
  88. ppTable -- address to receive ptr to cache data table
  89. Return Value:
  90. ERROR_SUCCES if successful.
  91. Error code on failure.
  92. --*/
  93. {
  94. DNS_STATUS status = ERROR_SUCCESS;
  95. DWORD rpcStatus = ERROR_SUCCESS;
  96. PDNS_RPC_CACHE_TABLE pcacheTable = NULL;
  97. DNSDBG( TRACE, ( "DnsGetCacheDataTable()\n" ));
  98. if ( ! ppTable )
  99. {
  100. return FALSE;
  101. }
  102. RpcTryExcept
  103. {
  104. status = CRrReadCache( NULL, &pcacheTable );
  105. }
  106. RpcExcept( DNS_RPC_EXCEPTION_FILTER )
  107. {
  108. status = RpcExceptionCode();
  109. }
  110. RpcEndExcept
  111. // set out param
  112. *ppTable = (PDNS_CACHE_TABLE) pcacheTable;
  113. #if DBG
  114. if ( status != ERROR_SUCCESS )
  115. {
  116. DNSDBG( RPC, (
  117. "DnsGetCacheDataTable() status = %d\n",
  118. status ));
  119. }
  120. #endif
  121. return( pcacheTable && status == ERROR_SUCCESS );
  122. }
  123. //
  124. // End dnsapi.c
  125. //