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.

212 lines
4.1 KiB

  1. /*++
  2. Copyright (c) 2001 Microsoft Corporation
  3. Module Name:
  4. Dfseventlog.cxx
  5. Abstract:
  6. This module defines APIs for logging events.
  7. Author:
  8. Rohan Phillips (Rohanp) 31-March-2001
  9. --*/
  10. #include <nt.h>
  11. #include <ntrtl.h>
  12. #include <nturtl.h>
  13. #include <windows.h>
  14. #include <dfsheader.h>
  15. #include "dfsinit.hxx"
  16. HANDLE
  17. DfsOpenEventLog(void)
  18. {
  19. DFSSTATUS Status = ERROR_SUCCESS;
  20. HANDLE EventLogHandle = NULL;
  21. EventLogHandle = RegisterEventSource( NULL, L"DfsSvc");
  22. if (EventLogHandle == NULL )
  23. {
  24. Status = GetLastError();
  25. }
  26. return EventLogHandle;
  27. }
  28. DFSSTATUS
  29. DfsCloseEventLog(HANDLE EventLogHandle)
  30. {
  31. DFSSTATUS Status = ERROR_SUCCESS;
  32. BOOL fSuccess = TRUE;
  33. if ( EventLogHandle != NULL)
  34. {
  35. fSuccess = DeregisterEventSource(EventLogHandle);
  36. if ( !fSuccess)
  37. {
  38. Status = GetLastError();
  39. }
  40. }
  41. return Status;
  42. }
  43. DFSSTATUS
  44. DfsLogEventEx(IN DWORD idMessage,
  45. IN WORD wEventType,
  46. IN WORD cSubstrings,
  47. IN LPCTSTR *rgszSubstrings,
  48. IN DWORD errCode)
  49. {
  50. DFSSTATUS Status = ERROR_SUCCESS;
  51. HANDLE EventLogHandle = NULL;
  52. void *pRawData = NULL;
  53. DWORD cbRawData = 0;
  54. if (DfsPostEventLog() == FALSE)
  55. {
  56. return Status;
  57. }
  58. //
  59. // Also include errCode in raw data form
  60. // where people can view it from EventViewer
  61. //
  62. if (errCode != 0) {
  63. cbRawData = sizeof(errCode);
  64. pRawData = &errCode;
  65. }
  66. EventLogHandle = DfsOpenEventLog();
  67. if(EventLogHandle != NULL)
  68. {
  69. //
  70. // log the event
  71. //
  72. if (!ReportEvent(EventLogHandle,
  73. wEventType,
  74. 0,
  75. idMessage,
  76. NULL,
  77. cSubstrings,
  78. cbRawData,
  79. rgszSubstrings,
  80. pRawData))
  81. {
  82. Status = GetLastError();
  83. }
  84. DfsCloseEventLog(EventLogHandle);
  85. }
  86. return Status;
  87. }
  88. DFSSTATUS
  89. DFsLogEvent(IN DWORD idMessage,
  90. IN const TCHAR * ErrorString,
  91. IN DWORD ErrCode)
  92. {
  93. DFSSTATUS Status = ERROR_SUCCESS;
  94. WORD wEventType = 0;
  95. const TCHAR * apszSubStrings[2];
  96. apszSubStrings[0] = ErrorString;
  97. if ( NT_INFORMATION( idMessage))
  98. {
  99. wEventType = EVENTLOG_INFORMATION_TYPE;
  100. }
  101. else if ( NT_WARNING( idMessage))
  102. {
  103. wEventType = EVENTLOG_WARNING_TYPE;
  104. }
  105. else
  106. {
  107. wEventType = EVENTLOG_ERROR_TYPE;
  108. }
  109. Status = DfsLogEventEx(idMessage,
  110. wEventType,
  111. 1,
  112. apszSubStrings,
  113. ErrCode);
  114. return Status;
  115. }
  116. //usage:
  117. // const TCHAR * apszSubStrings[4];
  118. // apszSubStrings[0] = L"Root1";
  119. // DfsLogDfsEvent(DFS_ERROR_ROOT_DELETION_FAILURE,
  120. // 1,
  121. // apszSubStrings,
  122. // errorcode);
  123. //
  124. //
  125. DFSSTATUS
  126. DfsLogDfsEvent(IN DWORD idMessage,
  127. IN WORD cSubStrings,
  128. IN const TCHAR * apszSubStrings[],
  129. IN DWORD ErrCode)
  130. {
  131. DFSSTATUS Status = ERROR_SUCCESS;
  132. WORD wEventType = 0;
  133. if ( NT_INFORMATION( idMessage))
  134. {
  135. wEventType = EVENTLOG_INFORMATION_TYPE;
  136. }
  137. else if ( NT_WARNING( idMessage))
  138. {
  139. wEventType = EVENTLOG_WARNING_TYPE;
  140. }
  141. else
  142. {
  143. wEventType = EVENTLOG_ERROR_TYPE;
  144. }
  145. Status = DfsLogEventEx(idMessage,
  146. wEventType,
  147. cSubStrings,
  148. apszSubStrings,
  149. ErrCode);
  150. return Status;
  151. }
  152. void
  153. DfsLogEventSimple(DWORD MessageId, DWORD ErrorCode=0)
  154. {
  155. DfsLogDfsEvent(MessageId, 0, NULL, ErrorCode);
  156. }