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.

180 lines
5.0 KiB

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