Source code of Windows XP (NT5)
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.

170 lines
3.6 KiB

  1. /*++
  2. Copyright (c) 1996-1999 Microsoft Corporation
  3. Module Name:
  4. event.c
  5. Abstract:
  6. DNS event logging.
  7. Author:
  8. Ramv June-02-1997
  9. Revision History:
  10. --*/
  11. #include "local.h"
  12. #define DNSAPI_LOG_SOURCE (L"DnsApi")
  13. //
  14. // Globals to suppress event logging
  15. //
  16. DWORD g_TimeLastDnsEvent = 0;
  17. DWORD g_DnsEventCount = 0;
  18. #define DNS_EVENTS_MAX_COUNT (5)
  19. #define DNS_EVENT_LOG_BLOCK_INTERVAL (1800) // 30 minutes
  20. VOID
  21. DnsLogEvent(
  22. IN DWORD MessageId,
  23. IN WORD EventType,
  24. IN DWORD NumberOfSubStrings,
  25. IN LPSTR * SubStrings,
  26. IN DWORD ErrorCode
  27. )
  28. {
  29. HANDLE logHandle;
  30. DWORD dataLength = 0;
  31. PVOID pdata = NULL;
  32. //
  33. // protect against log spin
  34. //
  35. // we'll allow a few events to log, then slam the door for
  36. // a while to avoid filling event log
  37. //
  38. // note: none of these protection structures are MT safe, but
  39. // there's no issue here, the failure mode is allowing an additional
  40. // log entry or denying one that should now be allowed; I don't
  41. // believe there's any failure mode that permanently turns logging
  42. // to always on or always off
  43. //
  44. if ( g_DnsEventCount > DNS_EVENTS_MAX_COUNT )
  45. {
  46. DWORD currentTime = Dns_GetCurrentTimeInSeconds();
  47. if ( g_TimeLastDnsEvent + DNS_EVENT_LOG_BLOCK_INTERVAL > currentTime )
  48. {
  49. DNS_PRINT((
  50. "DNSAPI: Refusing event logging!\n"
  51. "\tevent count = %d\n"
  52. "\tlast time = %d\n"
  53. "\tcurrent time = %d\n",
  54. g_DnsEventCount,
  55. g_TimeLastDnsEvent,
  56. currentTime ));
  57. return;
  58. }
  59. // interval has elapsed, clear counters and continue logging
  60. g_DnsEventCount = 0;
  61. }
  62. #if 0
  63. //
  64. // open event log -- if haven't already
  65. //
  66. // DCR_PERF: better to just open this and close on process detach?
  67. // will be open for services (maybe netlogon) but not much else
  68. //
  69. if ( !g_DnsEventlogHandle )
  70. {
  71. HANDLE hlog;
  72. hlog = RegisterEventSourceW(
  73. NULL,
  74. DNSAPI_LOG_SOURCE
  75. );
  76. if ( hlog == NULL )
  77. {
  78. DNS_PRINT(("DNSAPI : RegisterEventSourceA failed %lu\n",
  79. GetLastError()));
  80. return;
  81. }
  82. g_DnsEventlogHandle = hlog;
  83. }
  84. #endif
  85. //
  86. // open event log
  87. //
  88. logHandle = RegisterEventSourceW(
  89. NULL,
  90. DNSAPI_LOG_SOURCE
  91. );
  92. if ( logHandle == NULL )
  93. {
  94. DNS_PRINT(("DNSAPI : RegisterEventSourceA failed %lu\n",
  95. GetLastError()));
  96. return;
  97. }
  98. //
  99. // log the event
  100. // - get ptr and sizeof data
  101. //
  102. if ( ErrorCode != NO_ERROR )
  103. {
  104. dataLength = sizeof(DWORD);
  105. pdata = (PVOID) &ErrorCode;
  106. }
  107. //
  108. // DCR_FIX0: event logging should be unicode
  109. //
  110. ReportEventA(
  111. logHandle,
  112. EventType,
  113. 0, // event category
  114. MessageId,
  115. (PSID) NULL,
  116. (WORD) NumberOfSubStrings,
  117. dataLength,
  118. (LPSTR *)SubStrings,
  119. pdata );
  120. DeregisterEventSource( logHandle );
  121. //
  122. // successful logging spin protection
  123. // - inc count
  124. // - if at max, save last logging time
  125. //
  126. if ( ++g_DnsEventCount >= DNS_EVENTS_MAX_COUNT )
  127. {
  128. g_TimeLastDnsEvent = Dns_GetCurrentTimeInSeconds();
  129. }
  130. }
  131. //
  132. // End of event.c
  133. //