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.

178 lines
4.7 KiB

  1. #include "stdafx.h"
  2. #include "CertObj.h"
  3. #include "common.h"
  4. #include "certobjlog.h"
  5. HANDLE g_hEventLog = NULL;
  6. // #define EVENTLOG_SUCCESS 0x0000
  7. // #define EVENTLOG_ERROR_TYPE 0x0001
  8. // #define EVENTLOG_WARNING_TYPE 0x0002
  9. // #define EVENTLOG_INFORMATION_TYPE 0x0004
  10. // #define EVENTLOG_AUDIT_SUCCESS 0x0008
  11. // #define EVENTLOG_AUDIT_FAILURE 0x0010
  12. void EventlogReportEvent
  13. (
  14. WORD wType,
  15. DWORD dwEventID,
  16. LPCTSTR pFormat,
  17. ...
  18. )
  19. {
  20. TCHAR chMsg[256];
  21. HANDLE hEventSource;
  22. LPTSTR lpszStrings[1];
  23. va_list pArg;
  24. va_start(pArg, pFormat);
  25. _vstprintf(chMsg, pFormat, pArg);
  26. va_end(pArg);
  27. lpszStrings[0] = chMsg;
  28. if (g_hEventLog != NULL)
  29. {
  30. ReportEvent(g_hEventLog, wType, 0, dwEventID, NULL, 1, 0, (LPCTSTR*) &lpszStrings[0], NULL);
  31. }
  32. }
  33. BOOL EventlogRegistryInstall(void)
  34. {
  35. HKEY hKey;
  36. int err;
  37. DWORD disp;
  38. //
  39. // Create registry entries, whether event logging is currently
  40. // enabled or not.
  41. //
  42. err = RegCreateKeyEx( HKEY_LOCAL_MACHINE,
  43. TEXT("System\\CurrentControlSet\\Services\\EventLog\\System\\CertObj"),
  44. 0,
  45. TEXT(""),
  46. REG_OPTION_NON_VOLATILE,
  47. KEY_WRITE,
  48. NULL,
  49. &hKey,
  50. &disp);
  51. if (err)
  52. {
  53. return(FALSE);
  54. }
  55. if (disp == REG_CREATED_NEW_KEY)
  56. {
  57. RegSetValueEx( hKey,
  58. TEXT("EventMessageFile"),
  59. 0,
  60. REG_EXPAND_SZ,
  61. (PBYTE) TEXT("%SystemRoot%\\system32\\inetsrv\\certobj.dll"),
  62. sizeof(TEXT("%SystemRoot%\\system32\\inetsrv\\certobj.dll")));
  63. // disp = 7;
  64. disp = EVENTLOG_ERROR_TYPE |
  65. EVENTLOG_WARNING_TYPE |
  66. EVENTLOG_INFORMATION_TYPE ;
  67. RegSetValueEx( hKey,
  68. TEXT("TypesSupported"),
  69. 0,
  70. REG_DWORD,
  71. (PBYTE) &disp,
  72. sizeof(DWORD) );
  73. RegFlushKey(hKey);
  74. }
  75. RegCloseKey(hKey);
  76. return(TRUE);
  77. }
  78. void EventlogRegistryUnInstall(void)
  79. {
  80. HKEY hKey;
  81. DWORD dwStatus;
  82. TCHAR szBuf[MAX_PATH*2+1];
  83. // remove event source out of application and system
  84. _stprintf(szBuf, _TEXT("SYSTEM\\CurrentControlSet\\Services\\EventLog\\Application"));
  85. if((dwStatus=RegOpenKeyEx(HKEY_LOCAL_MACHINE, szBuf, 0, KEY_ALL_ACCESS, &hKey)) != ERROR_SUCCESS)
  86. {
  87. return;
  88. }
  89. RegDeleteKey(hKey, _T("CertObj"));
  90. RegCloseKey(hKey);
  91. _stprintf(szBuf, _TEXT("SYSTEM\\CurrentControlSet\\Services\\EventLog\\System"));
  92. if((dwStatus=RegOpenKeyEx(HKEY_LOCAL_MACHINE, szBuf, 0, KEY_ALL_ACCESS, &hKey)) != ERROR_SUCCESS)
  93. {
  94. return;
  95. }
  96. RegDeleteKey(hKey, _T("CertObj"));
  97. RegCloseKey(hKey);
  98. return;
  99. }
  100. void EventLogInit(void)
  101. {
  102. g_hEventLog = RegisterEventSource( NULL, L"CertObj" );
  103. return;
  104. }
  105. void EventLogCleanup(void)
  106. {
  107. if ( g_hEventLog != NULL )
  108. {
  109. DeregisterEventSource( g_hEventLog );
  110. g_hEventLog = NULL;
  111. }
  112. return;
  113. }
  114. void ReportIt(DWORD dwEventID, LPCTSTR szMetabasePath)
  115. {
  116. if (!g_hEventLog){EventLogInit();}
  117. switch (dwEventID)
  118. {
  119. case CERTOBJ_CERT_EXPORT_SUCCEED:
  120. EventlogReportEvent(EVENTLOG_INFORMATION_TYPE, dwEventID, szMetabasePath);
  121. break;
  122. case CERTOBJ_CERT_EXPORT_FAILED:
  123. EventlogReportEvent(EVENTLOG_INFORMATION_TYPE, dwEventID, szMetabasePath);
  124. break;
  125. case CERTOBJ_CERT_IMPORT_SUCCEED:
  126. EventlogReportEvent(EVENTLOG_INFORMATION_TYPE, dwEventID, szMetabasePath);
  127. break;
  128. case CERTOBJ_CERT_IMPORT_FAILED:
  129. EventlogReportEvent(EVENTLOG_INFORMATION_TYPE, dwEventID, szMetabasePath);
  130. break;
  131. case CERTOBJ_CERT_IMPORT_CERT_STORE_SUCCEED:
  132. EventlogReportEvent(EVENTLOG_INFORMATION_TYPE, dwEventID, szMetabasePath);
  133. break;
  134. case CERTOBJ_CERT_IMPORT_CERT_STORE_FAILED:
  135. EventlogReportEvent(EVENTLOG_INFORMATION_TYPE, dwEventID, szMetabasePath);
  136. break;
  137. case CERTOBJ_CERT_REMOVE_SUCCEED:
  138. EventlogReportEvent(EVENTLOG_INFORMATION_TYPE, dwEventID, szMetabasePath);
  139. break;
  140. case CERTOBJ_CERT_REMOVE_FAILED:
  141. EventlogReportEvent(EVENTLOG_INFORMATION_TYPE, dwEventID, szMetabasePath);
  142. break;
  143. default:
  144. break;
  145. }
  146. if (g_hEventLog) {EventLogCleanup();}
  147. return;
  148. }