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.

217 lines
7.3 KiB

  1. /*++
  2. Copyright (c) 2002 Microsoft Corporation
  3. Module Name:
  4. SceXMLLogWriter.h (interface of class SceXMLLogWriter)
  5. SceXMLLogWriter.cpp (implementation of class SceXMLLogWriter)
  6. Abstract:
  7. SceXMLLogWriter is a class that simplifies the XML Logging of SCE analysis
  8. data.
  9. It also serves to abstract away the actual log format from SCE.
  10. The user of this class need not be aware of the actual output
  11. log format thus allowing the format to be changed easily.
  12. Usage of this class is as follows. The class is initialized
  13. by calling its constructor. It is expected that COM has already
  14. been initialized when this constructor is called.
  15. Before logging any settings, SceXMLLogWriter::setNewArea must be called
  16. to set the current logging area. After this, the caller can call
  17. any combination of SceXMLLogWriter::setNewArea and SceXMLLogWriter::addSetting.
  18. Finally, SceXMLLogWriter::saveAs is called to save the output log file.
  19. Author:
  20. Steven Chan (t-schan) July 2002
  21. --*/
  22. #ifndef SCEXMLLOGWRITERH
  23. #define SCEXMLLOGWRITERH
  24. #include "secedit.h"
  25. #define ERROR_BUFFER_SIZE 80
  26. class SceXMLLogWriter {
  27. public:
  28. // SXTYPE represents the type of data being logged to SceXMLLogWriter::addSetting and
  29. // determines how the data will be represented in the log file.
  30. //
  31. // TYPE_DEFAULT defines the default representation for the datatype presented
  32. // to SceXMLLogWriter::addSetting depending on whether it is a DWORD or a PCWSTR
  33. //
  34. // TYPE_AUDIT defines audit data (0=none 1=onsuccess, 2=onfail, 3=both)
  35. //
  36. // TYPE_BOOLEAN defines (0=FALSE 1=TRUE)
  37. typedef enum _SXTYPE {
  38. TYPE_DEFAULT = 0,
  39. TYPE_AUDIT, // valid for DWORD else ignored
  40. TYPE_BOOLEAN, // valid for DWORD else ignored
  41. TYPE_REG_SZ, // REG types valid for strings
  42. TYPE_REG_EXPAND_SZ,
  43. TYPE_REG_BINARY,
  44. TYPE_REG_DWORD,
  45. TYPE_REG_MULTI_SZ
  46. } SXTYPE;
  47. // SXMATCH_STATUS defines the match status of the values being presented
  48. // to SceXMLLogWriter::addSetting.
  49. typedef enum _SXMATCH_STATUS {
  50. MATCH_TRUE,
  51. MATCH_FALSE,
  52. MATCH_NOT_DEFINED, // not defined in Baseline
  53. MATCH_NOT_CONFIGURED, // not configured in System
  54. MATCH_NOT_ANALYZED,
  55. MATCH_OTHER,
  56. MATCH_ERROR
  57. } SXMATCH_STATUS;
  58. SceXMLLogWriter();
  59. void SaveAs(PCWSTR szFileName);
  60. void SceXMLLogWriter::SetDescription(IN PCWSTR szMachineName,
  61. IN PCWSTR szProfileDescription,
  62. IN PCWSTR szAnalysisTimestamp);
  63. void SetNewArea(PCWSTR szAreaName);
  64. void AddSetting(PCWSTR szSettingName,
  65. PCWSTR szDescription,
  66. SXMATCH_STATUS match,
  67. DWORD baselineVal,
  68. DWORD systemVal,
  69. SXTYPE type);
  70. void AddSetting(PCWSTR szSettingName,
  71. PCWSTR szDescription,
  72. DWORD baselineVal,
  73. DWORD systemVal,
  74. SXTYPE type);
  75. void AddSetting(PCWSTR szSettingName,
  76. PCWSTR szDescription,
  77. PCWSTR szBaseline,
  78. PCWSTR szSystem,
  79. SXTYPE type);
  80. void AddSetting(PCWSTR szSettingName,
  81. PCWSTR szDescription,
  82. SXMATCH_STATUS match,
  83. PCWSTR szBaseline,
  84. PCWSTR szSystem,
  85. SXTYPE type);
  86. void AddSetting(PCWSTR szSettingName,
  87. PCWSTR szDescription,
  88. SXMATCH_STATUS match,
  89. PSCE_NAME_LIST pBaseline,
  90. PSCE_NAME_LIST pSystem,
  91. SXTYPE type);
  92. void AddSetting(PCWSTR szSettingName,
  93. PCWSTR szDescription,
  94. SXMATCH_STATUS match,
  95. PSCE_SERVICES pBaseline,
  96. PSCE_SERVICES pSystem,
  97. SXTYPE type);
  98. void AddSetting(PCWSTR szSettingName,
  99. PCWSTR szDescription,
  100. SXMATCH_STATUS match,
  101. PSCE_OBJECT_SECURITY pBaseline,
  102. PSCE_OBJECT_SECURITY pSystem,
  103. SXTYPE type);
  104. private:
  105. //
  106. // constants used by SceXMLLogWriter
  107. //
  108. static CComVariant _variantNodeElement;
  109. static CComBSTR _bstrMachineName;
  110. static CComBSTR _bstrProfileDescription;
  111. static CComBSTR _bstrAnalysisTimestamp;
  112. static CComBSTR _bstrSCEAnalysisData;
  113. static CComBSTR _bstrSetting;
  114. static CComBSTR _bstrAnalysisResult;
  115. static CComBSTR _bstrBaselineValue;
  116. static CComBSTR _bstrSystemValue;
  117. static CComBSTR _bstrType;
  118. static CComBSTR _bstrName;
  119. static CComBSTR _bstrMatch;
  120. static CComBSTR _bstrStartupType;
  121. static CComBSTR _bstrForever;
  122. static CComBSTR _bstrNotDefined;
  123. static CComBSTR _bstrNotAnalyzed;
  124. static CComBSTR _bstrNotConfigured;
  125. static CComBSTR _bstrOther;
  126. static CComBSTR _bstrTrue;
  127. static CComBSTR _bstrFalse;
  128. static CComBSTR _bstrError;
  129. static CComBSTR _bstrSpecial;
  130. static CComBSTR _bstrInteger;
  131. static CComBSTR _bstrBoolean;
  132. static CComBSTR _bstrSecurityDescriptor;
  133. static CComBSTR _bstrAccount;
  134. static CComBSTR _bstrAccounts;
  135. static CComBSTR _bstrEventAudit;
  136. static CComBSTR _bstrSuccess;
  137. static CComBSTR _bstrFailure;
  138. static CComBSTR _bstrServiceSetting;
  139. static CComBSTR _bstrBoot;
  140. static CComBSTR _bstrSystem;
  141. static CComBSTR _bstrAutomatic;
  142. static CComBSTR _bstrManual;
  143. static CComBSTR _bstrDisabled;
  144. static CComBSTR _bstrString;
  145. static CComBSTR _bstrRegSZ;
  146. static CComBSTR _bstrRegExpandSZ;
  147. static CComBSTR _bstrRegBinary;
  148. static CComBSTR _bstrRegDWORD;
  149. static CComBSTR _bstrRegMultiSZ;
  150. static CComBSTR _bstrDescription;
  151. //
  152. // variables that hold current logging state
  153. //
  154. CComPtr<IXMLDOMDocument> spXMLDOM; // the xml document
  155. CComPtr<IXMLDOMNode> spRootNode; // root node
  156. CComPtr<IXMLDOMNode> spCurrentArea; // note of current analysis area
  157. //
  158. // private methods
  159. //
  160. CComPtr<IXMLDOMNode> CreateNodeWithText(BSTR szNodeName, BSTR szText);
  161. CComPtr<IXMLDOMNode> CreateTypedNode(BSTR szNodeName, DWORD value, SXTYPE type);
  162. CComPtr<IXMLDOMNode> CreateTypedNode(BSTR szNodeName, BSTR value, SXTYPE type);
  163. CComPtr<IXMLDOMNode> CreateTypedNode(BSTR szNodeName, PSCE_NAME_LIST value, SXTYPE type);
  164. CComPtr<IXMLDOMNode> CreateTypedNode(BSTR szNodeName, PSCE_SERVICES value, SXTYPE type);
  165. CComPtr<IXMLDOMNode> CreateTypedNode(BSTR szNodeName, PSCE_OBJECT_SECURITY value, SXTYPE type);
  166. void AddSetting(BSTR bstrSettingName,
  167. BSTR bstrDescription,
  168. SXMATCH_STATUS match,
  169. IXMLDOMNode* spnBaseline,
  170. IXMLDOMNode* spnSystem);
  171. // for error checking
  172. static void CheckAppendChildResult(IN HRESULT hr);
  173. static void CheckCreateNodeResult(IN HRESULT hr);
  174. static void CheckCreatedCComBSTR(IN CComBSTR bstrIn);
  175. };
  176. #endif