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.

139 lines
3.0 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 PWSTR * 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. //
  63. // open event log
  64. //
  65. logHandle = RegisterEventSourceW(
  66. NULL,
  67. DNSAPI_LOG_SOURCE
  68. );
  69. if ( logHandle == NULL )
  70. {
  71. DNS_PRINT(("DNSAPI : RegisterEventSourceA failed %lu\n",
  72. GetLastError()));
  73. return;
  74. }
  75. //
  76. // log the event
  77. // - get ptr and sizeof data
  78. //
  79. if ( ErrorCode != NO_ERROR )
  80. {
  81. dataLength = sizeof(DWORD);
  82. pdata = (PVOID) &ErrorCode;
  83. }
  84. ReportEventW(
  85. logHandle,
  86. EventType,
  87. 0, // event category
  88. MessageId,
  89. (PSID) NULL,
  90. (WORD) NumberOfSubStrings,
  91. dataLength,
  92. SubStrings,
  93. pdata );
  94. DeregisterEventSource( logHandle );
  95. //
  96. // successful logging spin protection
  97. // - inc count
  98. // - if at max, save last logging time
  99. //
  100. if ( ++g_DnsEventCount >= DNS_EVENTS_MAX_COUNT )
  101. {
  102. g_TimeLastDnsEvent = Dns_GetCurrentTimeInSeconds();
  103. }
  104. }
  105. //
  106. // End of event.c
  107. //