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.

1954 lines
56 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. #ifdef UNICODE
  23. #define _UNICODE
  24. #endif
  25. #include <nt.h>
  26. #include <ntrtl.h>
  27. #include <nturtl.h>
  28. #include <windows.h>
  29. #include <iostream.h>
  30. #include <sddl.h>
  31. //
  32. // XML header files
  33. //
  34. #include <atlbase.h>
  35. //#include <atlconv.h>
  36. //#include <objbase.h>
  37. #include <msxml.h>
  38. #include "secedit.h"
  39. #include "SceXMLLogWriter.h"
  40. #include "SceLogException.h"
  41. #include "resource.h"
  42. //
  43. // define constants used by SceXMLLogWriterger
  44. //
  45. CComVariant SceXMLLogWriter::_variantNodeElement(NODE_ELEMENT);
  46. CComBSTR SceXMLLogWriter::_bstrMachineName("MachineName");
  47. CComBSTR SceXMLLogWriter::_bstrAnalysisTimestamp("AnalysisTimestamp");
  48. CComBSTR SceXMLLogWriter::_bstrProfileDescription("ProfileDescription");
  49. CComBSTR SceXMLLogWriter::_bstrSCEAnalysisData("SCEAnalysisData");
  50. CComBSTR SceXMLLogWriter::_bstrSetting("Setting");
  51. CComBSTR SceXMLLogWriter::_bstrDescription("Description");
  52. CComBSTR SceXMLLogWriter::_bstrAnalysisResult("AnalysisResult");
  53. CComBSTR SceXMLLogWriter::_bstrBaselineValue("BaselineValue");
  54. CComBSTR SceXMLLogWriter::_bstrSystemValue("SystemValue");
  55. CComBSTR SceXMLLogWriter::_bstrType("Type");
  56. CComBSTR SceXMLLogWriter::_bstrName("Name");
  57. CComBSTR SceXMLLogWriter::_bstrMatch("Match");
  58. CComBSTR SceXMLLogWriter::_bstrStartupType("StartupType");
  59. CComBSTR SceXMLLogWriter::_bstrForever("Forever");
  60. CComBSTR SceXMLLogWriter::_bstrNotDefined("Not Defined");
  61. CComBSTR SceXMLLogWriter::_bstrNotAnalyzed("Not Analyzed");
  62. CComBSTR SceXMLLogWriter::_bstrNotConfigured("Not Configured");
  63. CComBSTR SceXMLLogWriter::_bstrOther("Other");
  64. CComBSTR SceXMLLogWriter::_bstrTrue("TRUE");
  65. CComBSTR SceXMLLogWriter::_bstrFalse("FALSE");
  66. CComBSTR SceXMLLogWriter::_bstrError("Error");
  67. CComBSTR SceXMLLogWriter::_bstrSpecial("Special");
  68. CComBSTR SceXMLLogWriter::_bstrInteger("Integer");
  69. CComBSTR SceXMLLogWriter::_bstrBoolean("Boolean");
  70. CComBSTR SceXMLLogWriter::_bstrSecurityDescriptor("SecurityDescriptor");
  71. CComBSTR SceXMLLogWriter::_bstrAccount("Account");
  72. CComBSTR SceXMLLogWriter::_bstrAccounts("Accounts");
  73. CComBSTR SceXMLLogWriter::_bstrEventAudit("EventAudit");
  74. CComBSTR SceXMLLogWriter::_bstrSuccess("Success");
  75. CComBSTR SceXMLLogWriter::_bstrFailure("Failure");
  76. CComBSTR SceXMLLogWriter::_bstrServiceSetting("ServiceSetting");
  77. CComBSTR SceXMLLogWriter::_bstrBoot("Boot");
  78. CComBSTR SceXMLLogWriter::_bstrSystem("System");
  79. CComBSTR SceXMLLogWriter::_bstrAutomatic("Automatic");
  80. CComBSTR SceXMLLogWriter::_bstrManual("Manual");
  81. CComBSTR SceXMLLogWriter::_bstrDisabled("Disabled");
  82. CComBSTR SceXMLLogWriter::_bstrString("String");
  83. CComBSTR SceXMLLogWriter::_bstrRegSZ("REG_SZ");
  84. CComBSTR SceXMLLogWriter::_bstrRegExpandSZ("REG_EXPAND_SZ");
  85. CComBSTR SceXMLLogWriter::_bstrRegBinary("REG_BINARY");
  86. CComBSTR SceXMLLogWriter::_bstrRegDWORD("REG_DWORD");
  87. CComBSTR SceXMLLogWriter::_bstrRegMultiSZ("REG_MULTI_SZ");
  88. SceXMLLogWriter::SceXMLLogWriter()
  89. /*++
  90. Routine Description:
  91. Constructor for class SceXMLLogWriter.
  92. COM should be initialized before SceXMLLogWriter() is called as SceXMLLogWriter depends
  93. on MSXML in this current implementation.
  94. Arguments:
  95. none
  96. Throws:
  97. SceLogException*: on error initializing class
  98. Return Value:
  99. a new SceXMLLogWriter
  100. --*/
  101. {
  102. HRESULT hr;
  103. CComPtr<IXMLDOMNode> spTmpRootNode;
  104. try {
  105. //
  106. // check that strings were allocated successfully
  107. // else exception will be thrown
  108. //
  109. CheckCreatedCComBSTR(_bstrMachineName);
  110. CheckCreatedCComBSTR(_bstrProfileDescription);
  111. CheckCreatedCComBSTR(_bstrAnalysisTimestamp);
  112. CheckCreatedCComBSTR(_bstrSCEAnalysisData);
  113. CheckCreatedCComBSTR(_bstrSetting);
  114. CheckCreatedCComBSTR(_bstrAnalysisResult);
  115. CheckCreatedCComBSTR(_bstrBaselineValue);
  116. CheckCreatedCComBSTR(_bstrSystemValue);
  117. CheckCreatedCComBSTR(_bstrType);
  118. CheckCreatedCComBSTR(_bstrName);
  119. CheckCreatedCComBSTR(_bstrMatch);
  120. CheckCreatedCComBSTR(_bstrStartupType);
  121. CheckCreatedCComBSTR(_bstrForever);
  122. CheckCreatedCComBSTR(_bstrNotDefined);
  123. CheckCreatedCComBSTR(_bstrNotAnalyzed);
  124. CheckCreatedCComBSTR(_bstrNotConfigured);
  125. CheckCreatedCComBSTR(_bstrOther);
  126. CheckCreatedCComBSTR(_bstrTrue);
  127. CheckCreatedCComBSTR(_bstrFalse);
  128. CheckCreatedCComBSTR(_bstrError);
  129. CheckCreatedCComBSTR(_bstrSpecial);
  130. CheckCreatedCComBSTR(_bstrInteger);
  131. CheckCreatedCComBSTR(_bstrBoolean);
  132. CheckCreatedCComBSTR(_bstrSecurityDescriptor);
  133. CheckCreatedCComBSTR(_bstrAccount);
  134. CheckCreatedCComBSTR(_bstrAccounts);
  135. CheckCreatedCComBSTR(_bstrEventAudit);
  136. CheckCreatedCComBSTR(_bstrSuccess);
  137. CheckCreatedCComBSTR(_bstrFailure);
  138. CheckCreatedCComBSTR(_bstrServiceSetting);
  139. CheckCreatedCComBSTR(_bstrBoot);
  140. CheckCreatedCComBSTR(_bstrSystem);
  141. CheckCreatedCComBSTR(_bstrAutomatic);
  142. CheckCreatedCComBSTR(_bstrManual);
  143. CheckCreatedCComBSTR(_bstrDisabled);
  144. CheckCreatedCComBSTR(_bstrString);
  145. CheckCreatedCComBSTR(_bstrRegSZ);
  146. CheckCreatedCComBSTR(_bstrRegExpandSZ);
  147. CheckCreatedCComBSTR(_bstrRegBinary);
  148. CheckCreatedCComBSTR(_bstrRegDWORD);
  149. CheckCreatedCComBSTR(_bstrRegMultiSZ);
  150. CheckCreatedCComBSTR(_bstrDescription);
  151. //
  152. // create instance of MSXML
  153. //
  154. hr = spXMLDOM.CoCreateInstance(__uuidof(DOMDocument));
  155. if (FAILED(hr)) {
  156. throw new SceLogException(SceLogException::SXERROR_INIT_MSXML,
  157. L"CoCreateInstance(_uuidf(DOMDocument))",
  158. NULL,
  159. hr);
  160. }
  161. //
  162. // create and attach root node
  163. //
  164. hr = spXMLDOM->createNode(_variantNodeElement,
  165. _bstrSCEAnalysisData,
  166. NULL,
  167. &spTmpRootNode);
  168. CheckCreateNodeResult(hr);
  169. hr = spXMLDOM->appendChild(spTmpRootNode,
  170. &spRootNode);
  171. CheckAppendChildResult(hr);
  172. } catch (SceLogException *e) {
  173. e->AddDebugInfo(L"SceXMLLogWriter::SceXMLLogWriter()");
  174. throw e;
  175. } catch (...) {
  176. throw new SceLogException(SceLogException::SXERROR_INIT,
  177. L"SceXMLLogWriter::SceXMLLogWriter()",
  178. NULL,
  179. 0);
  180. }
  181. }
  182. void SceXMLLogWriter::SaveAs(PCWSTR szFileName)
  183. /*++
  184. Routine Description:
  185. Saves the current state of the log to szFileName
  186. Arguments:
  187. szFileName: filename to save as
  188. Throws:
  189. SceLogException*: on error while saving log
  190. Return Value:
  191. none
  192. --*/
  193. {
  194. HRESULT hr;
  195. // check arguments
  196. if (szFileName==NULL) {
  197. throw new SceLogException(SceLogException::SXERROR_SAVE_INVALID_FILENAME,
  198. L"IXMLDOMDocument->save(ILLEGAL ARG)",
  199. NULL,
  200. 0);
  201. }
  202. hr = spXMLDOM->save(CComVariant(szFileName));
  203. if (FAILED(hr)) {
  204. SceLogException::SXERROR errorType;
  205. // determine error code
  206. switch(hr){
  207. case E_INVALIDARG:
  208. errorType = SceLogException::SXERROR_SAVE_INVALID_FILENAME;
  209. break;
  210. case E_ACCESSDENIED:
  211. errorType = SceLogException::SXERROR_SAVE_ACCESS_DENIED;
  212. break;
  213. case E_OUTOFMEMORY:
  214. errorType = SceLogException::SXERROR_INSUFFICIENT_MEMORY;
  215. break;
  216. default:
  217. errorType = SceLogException::SXERROR_SAVE;
  218. break;
  219. }
  220. // create exception
  221. throw new SceLogException(errorType,
  222. L"IXMLDOMDocument->save()",
  223. NULL,
  224. hr);
  225. }
  226. }
  227. void
  228. SceXMLLogWriter::SetDescription(
  229. IN PCWSTR szMachineName,
  230. IN PCWSTR szProfileDescription,
  231. IN PCWSTR szAnalysisTimestamp
  232. )
  233. /*++
  234. Routine Description:
  235. Sets the description of the current logfile and places
  236. the description at the current position in the logfile
  237. Arguments:
  238. szMachineName: Machine name on which log is being exported
  239. szProfileDescription: Description of profile being exported
  240. szAnalysisTimeStamp: timestamp of last analysis
  241. Return Value:
  242. none
  243. Throws:
  244. SceLogException*
  245. --*/
  246. {
  247. HRESULT hr;
  248. CComPtr<IXMLDOMNode> spDescription, spMachineName, spAnalysisTimestamp,
  249. spProfileDescription;
  250. try {
  251. // create CComBSTRs
  252. CComBSTR bstrAnalysisTimestamp(szAnalysisTimestamp);
  253. CheckCreatedCComBSTR(bstrAnalysisTimestamp);
  254. CComBSTR bstrMachineName(szMachineName);
  255. CheckCreatedCComBSTR(bstrMachineName);
  256. CComBSTR bstrProfileDescription(szProfileDescription);
  257. CheckCreatedCComBSTR(bstrProfileDescription);
  258. // build description node
  259. spAnalysisTimestamp=CreateNodeWithText(_bstrAnalysisTimestamp,
  260. bstrAnalysisTimestamp);
  261. spMachineName=CreateNodeWithText(_bstrMachineName,
  262. bstrMachineName);
  263. spProfileDescription=CreateNodeWithText(_bstrProfileDescription,
  264. bstrProfileDescription);
  265. hr=spXMLDOM->createNode(_variantNodeElement,
  266. _bstrDescription,
  267. NULL,
  268. &spDescription);
  269. CheckCreateNodeResult(hr);
  270. hr=spDescription->appendChild(spMachineName, NULL);
  271. CheckAppendChildResult(hr);
  272. hr=spDescription->appendChild(spProfileDescription, NULL);
  273. CheckAppendChildResult(hr);
  274. hr=spDescription->appendChild(spAnalysisTimestamp, NULL);
  275. CheckAppendChildResult(hr);
  276. // append description node to root
  277. hr=spRootNode->appendChild(spDescription, NULL);
  278. CheckAppendChildResult(hr);
  279. } catch (SceLogException *e) {
  280. e->AddDebugInfo(L"SceXMLLogWriter::SetDescription(PCWSTR, PCWSTR, PCWSTR)");
  281. throw e;
  282. } catch (...) {
  283. throw new SceLogException(SceLogException::SXERROR_INTERNAL,
  284. L"SceXMLLogWriter::SetDescription(PCWSTR, PCWSTR, PCWSTR)",
  285. NULL,
  286. 0);
  287. }
  288. }
  289. void
  290. SceXMLLogWriter::SetNewArea(
  291. IN PCWSTR szAreaName
  292. )
  293. /*++
  294. Routine Description:
  295. Sets the current logging area to szAreaName. This should be called
  296. before attempting to log any settings.
  297. Arguments:
  298. szAreaName: Name of area. Must have no space, cannot be null nor empty
  299. Throws:
  300. SceLogException*:
  301. Return Value:
  302. none
  303. --*/
  304. {
  305. HRESULT hr;
  306. CComPtr<IXMLDOMNode> spTmpNewArea;
  307. // check arguments
  308. if ((szAreaName==NULL)||
  309. (wcscmp(szAreaName, L"")==0)) {
  310. throw new SceLogException(SceLogException::SXERROR_INTERNAL,
  311. L"SceXMLLogWriter::SetNewArea(ILLEGAL ARG)",
  312. NULL,
  313. 0);
  314. }
  315. try {
  316. // create CComBSTRs
  317. CComBSTR bstrAreaName(szAreaName);
  318. CheckCreatedCComBSTR(bstrAreaName);
  319. // create node structure and append to root
  320. hr = spXMLDOM->createNode(_variantNodeElement, bstrAreaName, NULL, &spTmpNewArea);
  321. CheckCreateNodeResult(hr);
  322. hr = spRootNode->appendChild(spTmpNewArea, &spCurrentArea);
  323. CheckAppendChildResult(hr);
  324. } catch (SceLogException *e) {
  325. e->AddDebugInfo(L"SceXMLLogWriter::SetNewArea(PCWSTR)");
  326. throw e;
  327. } catch (...) {
  328. throw new SceLogException(SceLogException::SXERROR_INTERNAL,
  329. L"SceXMLLogWriter::SetNewArea(PCWSTR)",
  330. NULL,
  331. 0);
  332. }
  333. }
  334. void
  335. SceXMLLogWriter::AddSetting(
  336. IN PCWSTR szSettingName,
  337. IN PCWSTR szSettingDescription,
  338. IN SXMATCH_STATUS match,
  339. IN DWORD baselineVal,
  340. IN DWORD systemVal,
  341. IN SXTYPE type
  342. )
  343. /*++
  344. Routine Description:
  345. Adds a new setting entry with the given values
  346. Arguments:
  347. szSettingName: Name of Setting
  348. szSettingDescription: Description of Setting
  349. match: SXMATCH_STATUS of setting
  350. baselineVal: baseline value
  351. systemVal; system value
  352. type: representation type
  353. Throws:
  354. SceLogException*:
  355. Return Value:
  356. none
  357. --*/
  358. {
  359. // check arguments
  360. if ((szSettingName==NULL) ||
  361. (wcscmp(szSettingName, L"")==0)) {
  362. throw new SceLogException(SceLogException::SXERROR_INTERNAL,
  363. L"SceXMLLogWriter::AddSetting(ILLEGAL ARG)",
  364. NULL,
  365. 0);
  366. }
  367. try {
  368. // create CComBSTRs
  369. CComBSTR bstrSettingName(szSettingName);
  370. CheckCreatedCComBSTR(bstrSettingName);
  371. CComBSTR bstrDescription(szDescription);
  372. CheckCreatedCComBSTR(bstrDescription);
  373. AddSetting(bstrSettingName,
  374. bstrDescription,
  375. match,
  376. CreateTypedNode(_bstrBaselineValue, baselineVal, type),
  377. CreateTypedNode(_bstrSystemValue, systemVal, type));
  378. } catch (SceLogException *e) {
  379. e->SetSettingName(szSettingName);
  380. e->AddDebugInfo(L"SceXMLLogWriter::AddSetting(PCWSTR, PCWSTR, SXMATCH_STATUS, DWORD, DWORD, SXTYPE)");
  381. throw e;
  382. } catch (...) {
  383. throw new SceLogException(SceLogException::SXERROR_INTERNAL,
  384. L"SceXMLLogWriter::AddSetting(PCWSTR, PCWSTR, SXMATCH_STATUS, DWORD, DWORD, SXTYPE)",
  385. NULL,
  386. 0);
  387. }
  388. }
  389. void
  390. SceXMLLogWriter::AddSetting(
  391. IN PCWSTR szSettingName,
  392. IN PCWSTR szSettingDescription,
  393. IN DWORD baselineVal,
  394. IN DWORD systemVal,
  395. IN SXTYPE type
  396. )
  397. /*++
  398. Routine Description:
  399. Adds a new setting entry with the given values
  400. Since the match status is not defined, this is determind
  401. from the values of baselineVal and systemVal using the
  402. conventions adhered to within the struct SCE_PROFILE_INFO
  403. Specifically,
  404. if (baselineVal==SCE_NO_VALUE) then MATCH_NOT_DEFINED
  405. if (systemVal==SCE_NO_VALUE)&&(baselineVal!=SCE_NO_VALUE)
  406. then match is set to MATCH_TRUE
  407. if (systemVal==SCE_NOT_ANALYZED) then MATCH_NOT_ANALYZED
  408. Arguments:
  409. szSettingName: Name of Setting
  410. szSettingDescription: Description of Setting
  411. baselineVal: baseline value
  412. systemVal; system value
  413. type: representation type
  414. Throws:
  415. SceLogException*:
  416. Return Value:
  417. none
  418. --*/
  419. {
  420. SXMATCH_STATUS match = MATCH_FALSE;
  421. CComPtr<IXMLDOMNode> spnBaseline, spnSystem;
  422. // check arguments
  423. if ((szSettingName==NULL) ||
  424. (wcscmp(szSettingName, L"")==0)) {
  425. throw new SceLogException(SceLogException::SXERROR_INTERNAL,
  426. L"SceXMLLogWriter::AddSetting(ILLEGAL ARG)",
  427. NULL,
  428. 0);
  429. }
  430. //
  431. // determine match status from systemVal and baselineVal
  432. //
  433. switch (systemVal) {
  434. case SCE_NO_VALUE:
  435. match = MATCH_TRUE;
  436. systemVal = baselineVal;
  437. break;
  438. case SCE_NOT_ANALYZED_VALUE:
  439. match = MATCH_NOT_ANALYZED;
  440. break;
  441. case SCE_ERROR_VALUE:
  442. match = MATCH_ERROR;
  443. break;
  444. case SCE_FOREVER_VALUE:
  445. case SCE_KERBEROS_OFF_VALUE:
  446. case SCE_DELETE_VALUE:
  447. case SCE_SNAPSHOT_VALUE:
  448. match = MATCH_OTHER;
  449. break;
  450. default:
  451. match = MATCH_FALSE;
  452. break;
  453. }
  454. // if baseline value not defined, this status precedes any
  455. // system value setting
  456. if (baselineVal == SCE_NO_VALUE) {
  457. match = MATCH_NOT_DEFINED;
  458. }
  459. //
  460. // add setting
  461. //
  462. try {
  463. // create CComBSTRs
  464. CComBSTR bstrSettingName(szSettingName);
  465. CheckCreatedCComBSTR(bstrSettingName);
  466. CComBSTR bstrSettingDescription(szSettingDescription);
  467. CheckCreatedCComBSTR(bstrSettingDescription);
  468. spnBaseline = CreateTypedNode(_bstrBaselineValue, baselineVal, type);
  469. spnSystem = CreateTypedNode(_bstrSystemValue, systemVal, type);
  470. AddSetting(bstrSettingName,
  471. bstrSettingDescription,
  472. match,
  473. spnBaseline,
  474. spnSystem);
  475. } catch (SceLogException *e) {
  476. e->SetSettingName(szSettingName);
  477. e->AddDebugInfo(L"SceXMLLogWriter::AddSetting(PCWSTR, PCWSTR, DWORD, DWORD, SXTYPE");
  478. throw e;
  479. } catch (...) {
  480. throw new SceLogException(SceLogException::SXERROR_INTERNAL,
  481. L"SceXMLLogWriter::AddSetting(PCWSTR, PCWSTR, DWORD, DWORD, SXTYPE",
  482. NULL,
  483. 0);
  484. }
  485. }
  486. void
  487. SceXMLLogWriter::AddSetting(
  488. IN PCWSTR szSettingName,
  489. IN PCWSTR szSettingDescription,
  490. IN PCWSTR szBaseline,
  491. IN PCWSTR szSystem,
  492. IN SXTYPE type
  493. )
  494. /*++
  495. Routine Description:
  496. Adds a new setting entry with the given values
  497. Since the match status is not defined, this is determind
  498. from the values of baselineVal and systemVal using the
  499. conventions adhered to within the struct SCE_PROFILE_INFO
  500. Specifically,
  501. if szBaseline==NULL then MATCH_NOT_DEFINED
  502. if szSystem==NULL and szBaseline!=NULL then MATCH_TRUE
  503. Arguments:
  504. szSettingName: Name of Setting
  505. szSettingDescription: Description of Setting
  506. baselineVal: baseline value
  507. systemVal; system value
  508. type: representation type
  509. Throws:
  510. SceLogException*
  511. Return Value:
  512. none
  513. --*/
  514. {
  515. SXMATCH_STATUS match = MATCH_FALSE;
  516. PCWSTR szSys;
  517. // check arguments
  518. if ((szSettingName==NULL) ||
  519. (wcscmp(szSettingName, L"")==0)) {
  520. throw new SceLogException(SceLogException::SXERROR_INTERNAL,
  521. L"SceXMLLogWriter::AddSetting(ILLEGAL ARG)",
  522. NULL,
  523. 0);
  524. }
  525. //
  526. // determine match status
  527. //
  528. szSys=szSystem;
  529. if (szSystem==NULL) {
  530. szSys=szBaseline;
  531. match = MATCH_TRUE;
  532. }
  533. if (szBaseline==NULL) {
  534. match = MATCH_NOT_DEFINED;
  535. }
  536. //
  537. // add setting
  538. //
  539. try {
  540. // create CComBSTRs
  541. CComBSTR bstrSettingName(szSettingName);
  542. CheckCreatedCComBSTR(bstrSettingName);
  543. CComBSTR bstrSettingDescription(szSettingDescription);
  544. CheckCreatedCComBSTR(bstrSettingDescription);
  545. CComBSTR bstrBaseline(szBaseline);
  546. if (szBaseline!=NULL) {
  547. CheckCreatedCComBSTR(bstrBaseline);
  548. }
  549. CComBSTR bstrSys(szSys);
  550. if (szSys!=NULL) {
  551. CheckCreatedCComBSTR(bstrSys);
  552. }
  553. AddSetting(bstrSettingName,
  554. bstrSettingDescription,
  555. match,
  556. CreateTypedNode(_bstrBaselineValue,
  557. bstrBaseline,
  558. type),
  559. CreateTypedNode(_bstrSystemValue,
  560. bstrSys,
  561. type));
  562. } catch (SceLogException *e) {
  563. e->SetSettingName(szSettingName);
  564. e->AddDebugInfo(L"SceXMLLogWriter::AddSetting(PCWSTR, PCWSTR, PCWSTR, PCWSTR, SXTYPE");
  565. throw e;
  566. } catch (...) {
  567. throw new SceLogException(SceLogException::SXERROR_INTERNAL,
  568. L"SceXMLLogWriter::AddSetting(PCWSTR, PCWSTR, PCWSTR, PCWSTR, SXTYPE",
  569. NULL,
  570. 0);
  571. }
  572. }
  573. void
  574. SceXMLLogWriter::AddSetting(
  575. IN PCWSTR szSettingName,
  576. IN PCWSTR szSettingDescription,
  577. IN SXMATCH_STATUS match,
  578. IN PCWSTR szBaseline,
  579. IN PCWSTR szSystem,
  580. IN SXTYPE type
  581. )
  582. /*++
  583. Routine Description:
  584. Adds a new setting entry with the given values
  585. Arguments:
  586. szSettingName: Name of Setting
  587. szSettingDescription: Description of Setting
  588. match: SXMATCH_STATUS of setting
  589. baselineVal: baseline value
  590. systemVal; system value
  591. type: representation type
  592. Throws:
  593. SceLogException*
  594. Return Value:
  595. none
  596. --*/
  597. {
  598. // check arguments
  599. if ((szSettingName==NULL) ||
  600. (wcscmp(szSettingName, L"")==0)) {
  601. throw new SceLogException(SceLogException::SXERROR_INTERNAL,
  602. L"SceXMLLogWriter::AddSetting(ILLEGAL ARG)",
  603. NULL,
  604. 0);
  605. }
  606. try {
  607. // create CComBSTRs
  608. CComBSTR bstrSettingName(szSettingName);
  609. CheckCreatedCComBSTR(bstrSettingName);
  610. CComBSTR bstrSettingDescription(szSettingDescription);
  611. CheckCreatedCComBSTR(bstrSettingDescription);
  612. CComBSTR bstrBaseline(szBaseline);
  613. if (szBaseline!=NULL) {
  614. CheckCreatedCComBSTR(bstrBaseline);
  615. }
  616. CComBSTR bstrSystem(szSystem);
  617. if (szSystem!=NULL) {
  618. CheckCreatedCComBSTR(bstrSystem);
  619. }
  620. AddSetting(bstrSettingName,
  621. bstrSettingDescription,
  622. match,
  623. CreateTypedNode(_bstrBaselineValue,
  624. bstrBaseline,
  625. type),
  626. CreateTypedNode(_bstrSystemValue,
  627. bstrSystem,
  628. type));
  629. } catch (SceLogException *e) {
  630. e->SetSettingName(szSettingName);
  631. e->AddDebugInfo(L"SceXMLLogWriter::AddSetting(PCWSTR, PCWSTR, SXMATCH_STATUS, PCWSTR, PCWSTR, SXTYPE");
  632. throw e;
  633. } catch (...) {
  634. throw new SceLogException(SceLogException::SXERROR_INTERNAL,
  635. L"SceXMLLogWriter::AddSetting(PCWSTR, PCWSTR, SXMATCH_STATUS, PCWSTR, PCWSTR, SXTYPE",
  636. NULL,
  637. 0);
  638. }
  639. }
  640. void
  641. SceXMLLogWriter::AddSetting(
  642. PCWSTR szSettingName,
  643. PCWSTR szSettingDescription,
  644. SXMATCH_STATUS match,
  645. PSCE_NAME_LIST pBaseline,
  646. PSCE_NAME_LIST pSystem,
  647. SXTYPE type
  648. )
  649. /*++
  650. Routine Description:
  651. Adds a new setting entry with the given values
  652. Arguments:
  653. szSettingName: Name of Setting
  654. szSettingDescription: Description of Setting
  655. match: SXMATCH_STATUS of setting
  656. baselineVal: baseline value
  657. systemVal; system value
  658. type: representation type
  659. Throws:
  660. SceLogException*
  661. Return Value:
  662. none
  663. --*/
  664. {
  665. CComPtr<IXMLDOMNode> spnBaseline, spnSystem;
  666. // check arguments
  667. if ((szSettingName==NULL) ||
  668. (wcscmp(szSettingName, L"")==0)) {
  669. throw new SceLogException(SceLogException::SXERROR_INTERNAL,
  670. L"SceXMLLogWriter::AddSetting(ILLEGAL ARG)",
  671. NULL,
  672. 0);
  673. }
  674. try {
  675. // create CComBSTRs
  676. CComBSTR bstrSettingName(szSettingName);
  677. CheckCreatedCComBSTR(bstrSettingName);
  678. CComBSTR bstrSettingDescription(szSettingDescription);
  679. CheckCreatedCComBSTR(bstrSettingDescription);
  680. spnBaseline = CreateTypedNode(_bstrBaselineValue, pBaseline, type);
  681. spnSystem = CreateTypedNode(_bstrSystemValue, pSystem, type);
  682. AddSetting(bstrSettingName,
  683. bstrSettingDescription,
  684. match,
  685. spnBaseline,
  686. spnSystem);
  687. } catch (SceLogException *e) {
  688. e->SetSettingName(szSettingName);
  689. e->AddDebugInfo(L"SceXMLLogWriter::AddSetting(PCWSTR, PCWSTR, SXMATCH_STATUS, PSCE_NAME_LIST, PSCE_NAME_LIST, SXTYPE");
  690. throw e;
  691. } catch (...) {
  692. throw new SceLogException(SceLogException::SXERROR_INTERNAL,
  693. L"SceXMLLogWriter::AddSetting(PCWSTR, PCWSTR, SXMATCH_STATUS, PSCE_NAME_LIST, PSCE_NAME_LIST, SXTYPE",
  694. NULL,
  695. 0);
  696. }
  697. }
  698. void
  699. SceXMLLogWriter::AddSetting(
  700. IN PCWSTR szSettingName,
  701. IN PCWSTR szSettingDescription,
  702. IN SXMATCH_STATUS match,
  703. IN PSCE_SERVICES pBaseline,
  704. IN PSCE_SERVICES pSystem,
  705. IN SXTYPE type
  706. )
  707. /*++
  708. Routine Description:
  709. Adds a new setting entry with the given values.
  710. Even though a list of services is presented, only the first
  711. service is logged.The rationale behind this is that the client
  712. needs to find the matching pointer to a particular service
  713. within two service lists that may have a different ordering.
  714. Arguments:
  715. szSettingName: Name of Setting
  716. szSettingDescription: Description of Setting
  717. match: SXMATCH_STATUS of setting
  718. baselineVal: baseline value
  719. systemVal; system value
  720. type: representation type
  721. Throws:
  722. SceLogException*
  723. Return Value:
  724. none
  725. --*/
  726. {
  727. CComPtr<IXMLDOMNode> spnBaseline, spnSystem;
  728. // check arguments
  729. if ((szSettingName==NULL) ||
  730. (wcscmp(szSettingName, L"")==0)) {
  731. throw new SceLogException(SceLogException::SXERROR_INTERNAL,
  732. L"SceXMLLogWriter::AddSetting(ILLEGAL ARG)",
  733. NULL,
  734. 0);
  735. }
  736. try {
  737. // create CComBSTRs
  738. CComBSTR bstrSettingName(szSettingName);
  739. CheckCreatedCComBSTR(bstrSettingName);
  740. CComBSTR bstrSettingDescription(szSettingDescription);
  741. CheckCreatedCComBSTR(bstrSettingDescription);
  742. spnBaseline = CreateTypedNode(_bstrBaselineValue, pBaseline, type);
  743. spnSystem = CreateTypedNode(_bstrSystemValue, pSystem, type);
  744. AddSetting(bstrSettingName,
  745. bstrSettingDescription,
  746. match,
  747. spnBaseline,
  748. spnSystem);
  749. } catch (SceLogException *e) {
  750. e->SetSettingName(szSettingName);
  751. e->AddDebugInfo(L"SceXMLLogWriter::AddSetting(PCWSTR, PCWSTR, SXMATCH_STATUS, PSCE_SERVICES, PSCE_SERVICES, SXTYPE");
  752. throw e;
  753. } catch (...) {
  754. throw new SceLogException(SceLogException::SXERROR_INTERNAL,
  755. L"SceXMLLogWriter::AddSetting(PCWSTR, PCWSTR, SXMATCH_STATUS, PSCE_SERVICES, PSCE_SERVICES, SXTYPE",
  756. NULL,
  757. 0);
  758. }
  759. }
  760. void
  761. SceXMLLogWriter::AddSetting(
  762. IN PCWSTR szSettingName,
  763. IN PCWSTR szSettingDescription,
  764. IN SXMATCH_STATUS match,
  765. IN PSCE_OBJECT_SECURITY pBaseline,
  766. IN PSCE_OBJECT_SECURITY pSystem,
  767. IN SXTYPE type
  768. )
  769. /*++
  770. Routine Description:
  771. Adds a new setting entry with the given values
  772. Arguments:
  773. szSettingName: Name of Setting
  774. szSettingDescription: Description of Setting
  775. match: SXMATCH_STATUS of setting
  776. baselineVal: baseline value
  777. systemVal; system value
  778. type: representation type
  779. Throws:
  780. SceLogException*
  781. Return Value:
  782. none
  783. --*/
  784. {
  785. CComPtr<IXMLDOMNode> spnBaseline, spnSystem;
  786. // check arguments
  787. if ((szSettingName==NULL) ||
  788. (wcscmp(szSettingName, L"")==0)) {
  789. throw new SceLogException(SceLogException::SXERROR_INTERNAL,
  790. L"SceXMLLogWriter::AddSetting(ILLEGAL ARG)",
  791. NULL,
  792. 0);
  793. }
  794. try {
  795. // create CComBSTRs
  796. CComBSTR bstrSettingName(szSettingName);
  797. CheckCreatedCComBSTR(bstrSettingName);
  798. CComBSTR bstrSettingDescription(szSettingDescription);
  799. CheckCreatedCComBSTR(bstrSettingDescription);
  800. spnBaseline = CreateTypedNode(_bstrBaselineValue, pBaseline, type);
  801. spnSystem = CreateTypedNode(_bstrSystemValue, pSystem, type);
  802. AddSetting(bstrSettingName,
  803. bstrSettingDescription,
  804. match,
  805. spnBaseline,
  806. spnSystem);
  807. } catch (SceLogException *e) {
  808. e->SetSettingName(szSettingName);
  809. e->AddDebugInfo(L"SceXMLLogWriter::AddSetting(PCWSTR, PCWSTR, SXMATCH_STATUS, PSCE_OBJECT_SECURITY, PSCE_OBJECT_SECURITY, SXTYPE");
  810. throw e;
  811. } catch (...) {
  812. throw new SceLogException(SceLogException::SXERROR_INTERNAL,
  813. L"SceXMLLogWriter::AddSetting(PCWSTR, PCWSTR, SXMATCH_STATUS, PSCE_OBJECT_SECURITY, PSCE_OBJECT_SECURITY, SXTYPE",
  814. NULL,
  815. 0);
  816. }
  817. }
  818. //
  819. // Private Functions!
  820. //
  821. CComPtr<IXMLDOMNode>
  822. SceXMLLogWriter::CreateNodeWithText(
  823. IN BSTR bstrNodeName,
  824. IN BSTR bstrText
  825. )
  826. /*++
  827. Routine Description:
  828. This private method creates a node with name bstrNodeName and text
  829. as specified by bstrText.
  830. This method is private so as to abstract the logging implementation
  831. (currently XML) from the client.
  832. Arguments:
  833. bstrNodeName: Name of node to create. Must have NO spaces.
  834. bstrText: Text that this node should contain
  835. Return Value:
  836. CComPtr<IXMLDOMNode>
  837. Throws:
  838. SceLogException*
  839. --*/
  840. {
  841. CComPtr<IXMLDOMText> sptnTextNode;
  842. CComPtr<IXMLDOMNode> spnNodeWithText;
  843. HRESULT hr;
  844. //
  845. // create the text node, create the actual node,
  846. // then add text node to actual node
  847. //
  848. try {
  849. hr = spXMLDOM->createTextNode(bstrText, &sptnTextNode);
  850. CheckCreateNodeResult(hr);
  851. hr = spXMLDOM->createNode(_variantNodeElement, bstrNodeName, NULL, &spnNodeWithText);
  852. CheckCreateNodeResult(hr);
  853. hr = spnNodeWithText->appendChild(sptnTextNode, NULL);
  854. CheckAppendChildResult(hr);
  855. } catch (SceLogException *e) {
  856. e->AddDebugInfo(L"SceXMLLogWriter::CreateNodeWithText(BSTR, BSTR)");
  857. throw e;
  858. } catch (...) {
  859. throw new SceLogException(SceLogException::SXERROR_INTERNAL,
  860. L"SceXMLLogWriter::CreateNodeWithText(BSTR, BSTR)",
  861. NULL,
  862. 0);
  863. }
  864. return spnNodeWithText;
  865. }
  866. CComPtr<IXMLDOMNode>
  867. SceXMLLogWriter::CreateTypedNode(
  868. IN BSTR bstrNodeName,
  869. IN PSCE_SERVICES value,
  870. IN SXTYPE type
  871. )
  872. /*++
  873. Routine Description:
  874. This private method creates a specially formated node that stores
  875. service information with the representation as specified by 'type'
  876. This method is private so as to abstract the logging implementation
  877. (currently XML) from the client.
  878. Arguments:
  879. bstrNodeName: Name of node to create. Must have NO spaces.
  880. value: Data that this node is to contain
  881. type: Species how this data should be represented
  882. Return Value:
  883. CComPtr<IXMLDOMNode
  884. Throws:
  885. SceLogException*
  886. --*/
  887. {
  888. CComPtr<IXMLDOMNode> result, spnodSD, spnodStartupType;
  889. PWSTR szSD = NULL;
  890. BOOL bConvertResult = FALSE;
  891. HRESULT hr;
  892. try {
  893. if (value==NULL) {
  894. result = CreateNodeWithText(bstrNodeName, _bstrNotDefined);
  895. } else {
  896. bConvertResult = ConvertSecurityDescriptorToStringSecurityDescriptor(
  897. value->General.pSecurityDescriptor,
  898. SDDL_REVISION_1,
  899. value->SeInfo,
  900. &szSD,
  901. NULL);
  902. if (bConvertResult==FALSE) {
  903. throw new SceLogException(SceLogException::SXERROR_INTERNAL,
  904. L"ConvertSecurityDescriptorToStringSecurityDescriptor()",
  905. NULL,
  906. 0);
  907. }
  908. CComBSTR bstrSD(szSD);
  909. CheckCreatedCComBSTR(bstrSD);
  910. spnodSD=CreateNodeWithText(_bstrSecurityDescriptor, bstrSD);
  911. //
  912. // determine service startup type
  913. //
  914. switch (value->Startup) {
  915. case SCE_STARTUP_BOOT:
  916. spnodStartupType=CreateNodeWithText(_bstrStartupType, _bstrBoot);
  917. break;
  918. case SCE_STARTUP_SYSTEM:
  919. spnodStartupType=CreateNodeWithText(_bstrStartupType, _bstrSystem);
  920. break;
  921. case SCE_STARTUP_AUTOMATIC:
  922. spnodStartupType=CreateNodeWithText(_bstrStartupType, _bstrAutomatic);
  923. break;
  924. case SCE_STARTUP_MANUAL:
  925. spnodStartupType=CreateNodeWithText(_bstrStartupType, _bstrManual);
  926. break;
  927. case SCE_STARTUP_DISABLED:
  928. spnodStartupType=CreateNodeWithText(_bstrStartupType, _bstrDisabled);
  929. break;
  930. }
  931. //
  932. // append startup type descriptor node
  933. //
  934. hr = spXMLDOM->createNode(_variantNodeElement, bstrNodeName, NULL, &result);
  935. CheckCreateNodeResult(hr);
  936. result->appendChild(spnodStartupType, NULL);
  937. result->appendChild(spnodSD, NULL);
  938. //
  939. // Cast as element to add attribute
  940. //
  941. CComQIPtr<IXMLDOMElement> speResult;
  942. speResult = result;
  943. if (speResult.p == NULL) {
  944. throw new SceLogException(SceLogException::SXERROR_INTERNAL,
  945. L"CComQIPtr<IXMLDOMElement> x = IXMLDOMNode y",
  946. NULL,
  947. 0);
  948. }
  949. hr = speResult->setAttribute(_bstrType, CComVariant(_bstrServiceSetting));
  950. if (FAILED(hr)) {
  951. throw new SceLogException(SceLogException::SXERROR_INTERNAL,
  952. L"IXMLDOMElement->setAttribute()",
  953. NULL,
  954. hr);
  955. }
  956. }
  957. } catch (SceLogException *e) {
  958. if (NULL!=szSD) {
  959. LocalFree(szSD);
  960. szSD=NULL;
  961. }
  962. e->AddDebugInfo(L"SceXMLLogWriter::CreateTypedNode(BSTR, PSCE_SERVICES, SXTYPE)");
  963. throw e;
  964. } catch (...) {
  965. if (NULL!=szSD) {
  966. LocalFree(szSD);
  967. szSD=NULL;
  968. }
  969. throw new SceLogException(SceLogException::SXERROR_INTERNAL,
  970. L"SceXMLLogWriter::CreateTypedNode(BSTR, PSCE_SERVICES, SXTYPE)",
  971. NULL,
  972. 0);
  973. }
  974. //
  975. // cleanup
  976. //
  977. if (NULL!=szSD) {
  978. LocalFree(szSD);
  979. szSD=NULL;
  980. }
  981. return result;
  982. }
  983. CComPtr<IXMLDOMNode>
  984. SceXMLLogWriter::CreateTypedNode(
  985. IN BSTR bstrNodeName,
  986. IN PSCE_OBJECT_SECURITY value,
  987. IN SXTYPE type)
  988. /*++
  989. Routine Description:
  990. This private method creates a specially formated node that stores
  991. object security information with the representation as specified by 'type'
  992. This method is private so as to abstract the logging implementation
  993. (currently XML) from the client.
  994. Arguments:
  995. bstrNodeName: Name of node to create. Must have NO spaces.
  996. value: Data that this node is to contain
  997. type: Species how this data should be represented
  998. Return Value:
  999. CComPtr<IXMLDOMNode>
  1000. Throws:
  1001. SceLogException*
  1002. --*/
  1003. {
  1004. CComPtr<IXMLDOMNode> result;
  1005. PWSTR szSD = NULL;
  1006. BOOL bConvertResult = FALSE;
  1007. HRESULT hr;
  1008. try {
  1009. if (value==NULL) {
  1010. result = CreateNodeWithText(bstrNodeName, _bstrNotDefined);
  1011. } else {
  1012. //
  1013. // convert security descriptor to string
  1014. //
  1015. bConvertResult = ConvertSecurityDescriptorToStringSecurityDescriptor(
  1016. value->pSecurityDescriptor,
  1017. SDDL_REVISION_1,
  1018. value->SeInfo,
  1019. &szSD,
  1020. NULL);
  1021. if (bConvertResult==FALSE) {
  1022. throw new SceLogException(SceLogException::SXERROR_INTERNAL,
  1023. L"ConvertSecurityDescriptorToStringSecurityDescriptor()",
  1024. NULL,
  1025. 0);
  1026. }
  1027. CComBSTR bstrSD(szSD);
  1028. CheckCreatedCComBSTR(bstrSD);
  1029. result=CreateNodeWithText(bstrNodeName, bstrSD);
  1030. //
  1031. // Cast as element to add attribute
  1032. //
  1033. CComQIPtr<IXMLDOMElement> speResult;
  1034. speResult = result;
  1035. if (speResult.p == NULL) {
  1036. throw new SceLogException(SceLogException::SXERROR_INTERNAL,
  1037. L"CComQIPtr<IXMLDOMElement> x = IXMLDOMNode y",
  1038. NULL,
  1039. 0);
  1040. }
  1041. hr = speResult->setAttribute(_bstrType, CComVariant(_bstrSecurityDescriptor));
  1042. if (FAILED(hr)) {
  1043. throw new SceLogException(SceLogException::SXERROR_INTERNAL,
  1044. L"IXMLDOMElement->setAttribute()",
  1045. NULL,
  1046. hr);
  1047. }
  1048. }
  1049. } catch (SceLogException *e) {
  1050. if (NULL!=szSD) {
  1051. LocalFree(szSD);
  1052. szSD=NULL;
  1053. }
  1054. e->AddDebugInfo(L"SceXMLLogWriter::CreateTypedNode(BSTR, PSCE_OBJECT_SECURITY, SXTYPE)");
  1055. throw e;
  1056. } catch (...) {
  1057. if (NULL!=szSD) {
  1058. LocalFree(szSD);
  1059. szSD=NULL;
  1060. }
  1061. throw new SceLogException(SceLogException::SXERROR_INTERNAL,
  1062. L"SceXMLLogWriter::CreateTypedNode(BSTR, PSCE_OBJECT_SECURITY, SXTYPE)",
  1063. NULL,
  1064. 0);
  1065. }
  1066. //
  1067. // cleanup
  1068. //
  1069. if (NULL!=szSD) {
  1070. LocalFree(szSD);
  1071. szSD=NULL;
  1072. }
  1073. return result;
  1074. }
  1075. CComPtr<IXMLDOMNode>
  1076. SceXMLLogWriter::CreateTypedNode(
  1077. IN BSTR bstrNodeName,
  1078. IN PSCE_NAME_LIST value,
  1079. IN SXTYPE type
  1080. )
  1081. /*++
  1082. Routine Description:
  1083. This private method creates a specially formated node that stores
  1084. SCE_NAME_LISTs with the representation as specified by 'type'
  1085. This method is private so as to abstract the logging implementation
  1086. (currently XML) from the client.
  1087. Arguments:
  1088. bstrNodeName: Name of node to create. Must have NO spaces.
  1089. value: Data that this node is to contain
  1090. type: Species how this data should be represented
  1091. Return Value:
  1092. CComPtr<IXMLDOMNode>
  1093. Throws:
  1094. SceLogException*
  1095. --*/
  1096. {
  1097. CComPtr<IXMLDOMNode> result, temp;
  1098. PSCE_NAME_LIST tMem1;
  1099. HRESULT hr;
  1100. try {
  1101. hr = spXMLDOM->createNode(_variantNodeElement, bstrNodeName, NULL, &result);
  1102. CheckCreateNodeResult(hr);
  1103. tMem1 = value;
  1104. while (tMem1!=NULL) {
  1105. temp = CreateNodeWithText(_bstrAccount, tMem1->Name);
  1106. hr = result->appendChild(temp, NULL);
  1107. CheckAppendChildResult(hr);
  1108. tMem1=tMem1->Next;
  1109. }
  1110. //
  1111. // Cast as element to add attribute
  1112. //
  1113. CComQIPtr<IXMLDOMElement> speResult;
  1114. speResult = result;
  1115. if (speResult.p == NULL) {
  1116. throw new SceLogException(SceLogException::SXERROR_INTERNAL,
  1117. L"CComQIPtr<IXMLDOMElement> x = IXMLDOMNode y",
  1118. NULL,
  1119. 0);
  1120. }
  1121. hr = speResult->setAttribute(_bstrType, CComVariant(_bstrAccounts));
  1122. if (FAILED(hr)) {
  1123. throw new SceLogException(SceLogException::SXERROR_INTERNAL,
  1124. L"IXMLDOMElement->setAttribute()",
  1125. NULL,
  1126. hr);
  1127. }
  1128. } catch (SceLogException *e) {
  1129. e->AddDebugInfo(L"SceXMLLogWriter::CreateTypedNode(BSTR, PSCE_NAME_LIST, SXTYPE)");
  1130. throw e;
  1131. } catch (...) {
  1132. throw new SceLogException(SceLogException::SXERROR_INTERNAL,
  1133. L"SceXMLLogWriter::CreateTypedNode(BSTR, PSCE_NAME_LIST, SXTYPE)",
  1134. NULL,
  1135. 0);
  1136. }
  1137. return result;
  1138. }
  1139. CComPtr<IXMLDOMNode>
  1140. SceXMLLogWriter::CreateTypedNode(
  1141. IN BSTR bstrNodeName,
  1142. IN DWORD value,
  1143. IN SXTYPE type
  1144. )
  1145. /*++
  1146. Routine Description:
  1147. This private method creates a specially formated node that stores
  1148. DWORDs with the representation as specified by 'type'
  1149. This method is private so as to abstract the logging implementation
  1150. (currently XML) from the client.
  1151. Arguments:
  1152. bstrNodeName: Name of node to create. Must have NO spaces.
  1153. value: Data that this node is to contain
  1154. type: Species how this data should be represented
  1155. Return Value:
  1156. CComPtr<IXMLDOMNode>
  1157. Throws:
  1158. SceLogException*
  1159. --*/
  1160. {
  1161. CComPtr<IXMLDOMNode> result;
  1162. WCHAR buffer[20];
  1163. HRESULT hr;
  1164. BSTR bstrType = NULL;
  1165. try {
  1166. // first check for any special value types: {forever, not defined, not analyzed}
  1167. switch (value) {
  1168. case SCE_FOREVER_VALUE:
  1169. result = CreateNodeWithText(bstrNodeName, _bstrForever);
  1170. bstrType = _bstrSpecial;
  1171. break;
  1172. case SCE_NO_VALUE:
  1173. result = CreateNodeWithText(bstrNodeName, _bstrNotDefined);
  1174. bstrType = _bstrSpecial;
  1175. break;
  1176. case SCE_NOT_ANALYZED_VALUE:
  1177. result = CreateNodeWithText(bstrNodeName, _bstrNotAnalyzed);
  1178. bstrType = _bstrSpecial;
  1179. break;
  1180. default:
  1181. // otherwise format by specified type
  1182. switch (type) {
  1183. case TYPE_DEFAULT:
  1184. _itot(value, buffer, 10);
  1185. result = CreateNodeWithText(bstrNodeName, buffer);
  1186. bstrType = _bstrInteger;
  1187. break;
  1188. case TYPE_BOOLEAN:
  1189. bstrType = _bstrBoolean;
  1190. if (value==0) {
  1191. result = CreateNodeWithText(bstrNodeName, _bstrFalse);
  1192. } else {
  1193. result = CreateNodeWithText(bstrNodeName, _bstrTrue);
  1194. }
  1195. break;
  1196. case TYPE_AUDIT:
  1197. CComPtr<IXMLDOMNode> spnSuccess, spnFailure;
  1198. if (value & 0x01) {
  1199. spnSuccess = CreateNodeWithText(_bstrSuccess, _bstrTrue);
  1200. } else {
  1201. spnSuccess = CreateNodeWithText(_bstrSuccess, _bstrFalse);
  1202. }
  1203. if (value & 0x02) {
  1204. spnFailure = CreateNodeWithText(_bstrFailure, _bstrTrue);
  1205. } else {
  1206. spnFailure = CreateNodeWithText(_bstrFailure, _bstrFalse);
  1207. }
  1208. hr=spXMLDOM->createNode(_variantNodeElement, bstrNodeName, NULL, &result);
  1209. CheckCreateNodeResult(hr);
  1210. hr = result->appendChild(spnSuccess, NULL);
  1211. CheckAppendChildResult(hr);
  1212. hr = result->appendChild(spnFailure, NULL);
  1213. CheckAppendChildResult(hr);
  1214. bstrType = _bstrEventAudit;
  1215. break;
  1216. }
  1217. }
  1218. // Cast as element to add attribute
  1219. CComQIPtr<IXMLDOMElement> speResult;
  1220. speResult = result;
  1221. if (speResult.p == NULL) {
  1222. throw new SceLogException(SceLogException::SXERROR_INTERNAL,
  1223. L"CComQIPtr<IXMLDOMElement> x = IXMLDOMNode y",
  1224. NULL,
  1225. 0);
  1226. }
  1227. hr = speResult->setAttribute(_bstrType, CComVariant(bstrType));
  1228. if (FAILED(hr)) {
  1229. throw new SceLogException(SceLogException::SXERROR_INTERNAL,
  1230. L"IXMLDOMElement->setAttribute()",
  1231. NULL,
  1232. hr);
  1233. }
  1234. } catch (SceLogException *e) {
  1235. e->AddDebugInfo(L"SceXMLLogWriter::CreateTypedNode(BSTR, DWORD, SXTYPE)");
  1236. throw e;
  1237. } catch (...) {
  1238. throw new SceLogException(SceLogException::SXERROR_INTERNAL,
  1239. L"SceXMLLogWriter::CreateTypedNode(BSTR, DWORD, SXTYPE)",
  1240. NULL,
  1241. 0);
  1242. }
  1243. return result;
  1244. }
  1245. CComPtr<IXMLDOMNode>
  1246. SceXMLLogWriter::CreateTypedNode(
  1247. IN BSTR bstrNodeName,
  1248. IN BSTR bstrValue,
  1249. IN SXTYPE type
  1250. )
  1251. /*++
  1252. Routine Description:
  1253. This private method creates a specially formated node that stores
  1254. strings with the representation as specified by 'type'
  1255. This method is private so as to abstract the logging implementation
  1256. (currently XML) from the client.
  1257. Arguments:
  1258. bstrNodeName: Name of node to create. Must have NO spaces.
  1259. bstrValue: Data that this node is to contain
  1260. type: Species how this data should be represented
  1261. Return Value:
  1262. CComPtr<IXMLDOMNode>
  1263. Throws:
  1264. SceLogException*
  1265. --*/
  1266. {
  1267. CComPtr<IXMLDOMNode> result;
  1268. BSTR bstrType=NULL;
  1269. HRESULT hr;
  1270. //
  1271. // determine registry value type
  1272. //
  1273. switch(type) {
  1274. case TYPE_DEFAULT:
  1275. bstrType=_bstrString;
  1276. break;
  1277. case TYPE_REG_SZ:
  1278. bstrType=_bstrRegSZ;
  1279. break;
  1280. case TYPE_REG_EXPAND_SZ:
  1281. bstrType=_bstrRegExpandSZ;
  1282. break;
  1283. case TYPE_REG_BINARY:
  1284. bstrType=_bstrRegBinary;
  1285. break;
  1286. case TYPE_REG_DWORD:
  1287. bstrType=_bstrRegDWORD;
  1288. break;
  1289. case TYPE_REG_MULTI_SZ:
  1290. bstrType=_bstrRegMultiSZ;
  1291. break;
  1292. default:
  1293. bstrType=_bstrString;
  1294. }
  1295. try {
  1296. if (bstrValue==NULL) {
  1297. result=CreateNodeWithText(bstrNodeName, _bstrNotDefined);
  1298. } else {
  1299. result=CreateNodeWithText(bstrNodeName, bstrValue);
  1300. }
  1301. // Cast as element to add attribute
  1302. CComQIPtr<IXMLDOMElement> speResult;
  1303. speResult = result;
  1304. if (speResult.p == NULL) {
  1305. throw new SceLogException(SceLogException::SXERROR_INTERNAL,
  1306. L"CComQIPtr<IXMLDOMElement> x = IXMLDOMNode y",
  1307. NULL,
  1308. 0);
  1309. }
  1310. hr=speResult->setAttribute(_bstrType, CComVariant(bstrType));
  1311. if (FAILED(hr)) {
  1312. throw new SceLogException(SceLogException::SXERROR_INTERNAL,
  1313. L"IXMLDOMElement->setAttribute()",
  1314. NULL,
  1315. hr);
  1316. }
  1317. } catch (SceLogException *e) {
  1318. e->AddDebugInfo(L"SceXMLLogWriter::createTypedNode(PCWSTR, BSTR, SXTYPE)");
  1319. throw e;
  1320. } catch (...) {
  1321. throw new SceLogException(SceLogException::SXERROR_INTERNAL,
  1322. L"SceXMLLogWriter::createTypedNode(PCWSTR, BSTR, SXTYPE)",
  1323. NULL,
  1324. 0);
  1325. }
  1326. return result;
  1327. }
  1328. void
  1329. SceXMLLogWriter::AddSetting(
  1330. IN BSTR bstrSettingName,
  1331. IN BSTR bstrSettingDescription,
  1332. IN SXMATCH_STATUS match,
  1333. IN IXMLDOMNode* spnBaseline,
  1334. IN IXMLDOMNode* spnSystem
  1335. )
  1336. /*++
  1337. Routine Description:
  1338. This private method inserts a setting into the current area with match
  1339. status match,baseline node spnBaseline and system setting node spnSystem
  1340. This method is private so as to abstract the logging implementation
  1341. (currently XML) from the client.
  1342. Arguments:
  1343. bstrSettingName: Name of setting to add
  1344. bstrSettingDescription: Description of setting
  1345. match: match status
  1346. spnBaseLine: Baseline Node to attach
  1347. spnSystem: System Setting Node to attach
  1348. Return Value:
  1349. none
  1350. Throws:
  1351. SceLogException*
  1352. --*/
  1353. {
  1354. HRESULT hr;
  1355. CComPtr<IXMLDOMNode> spSetting, spAnalysisResult;
  1356. CComPtr<IXMLDOMNode> spSettingName, spMatchStatus, spSettingDescription;
  1357. try {
  1358. //
  1359. // construct Setting
  1360. //
  1361. hr = spXMLDOM->createNode(_variantNodeElement, _bstrSetting, NULL, &spSetting);
  1362. CheckCreateNodeResult(hr);
  1363. spSettingName = CreateNodeWithText(_bstrName, bstrSettingName);
  1364. spSettingDescription = CreateNodeWithText(_bstrDescription, bstrSettingDescription);
  1365. hr = spSetting->appendChild(spSettingName, NULL);
  1366. CheckCreateNodeResult(hr);
  1367. hr = spSetting->appendChild(spSettingDescription, NULL);
  1368. CheckCreateNodeResult(hr);
  1369. //
  1370. // construct Anyalysis Result
  1371. //
  1372. hr = spXMLDOM->createNode(_variantNodeElement, _bstrAnalysisResult, NULL, &spAnalysisResult);
  1373. CheckCreateNodeResult(hr);
  1374. switch(match) {
  1375. case MATCH_TRUE:
  1376. spMatchStatus = CreateNodeWithText(_bstrMatch, _bstrTrue);
  1377. break;
  1378. case MATCH_FALSE:
  1379. spMatchStatus = CreateNodeWithText(_bstrMatch, _bstrFalse);
  1380. break;
  1381. case MATCH_OTHER:
  1382. spMatchStatus = CreateNodeWithText(_bstrMatch, _bstrOther);
  1383. break;
  1384. case MATCH_NOT_DEFINED:
  1385. spMatchStatus = CreateNodeWithText(_bstrMatch, _bstrNotDefined);
  1386. break;
  1387. case MATCH_NOT_ANALYZED:
  1388. spMatchStatus = CreateNodeWithText(_bstrMatch, _bstrNotAnalyzed);
  1389. break;
  1390. case MATCH_NOT_CONFIGURED:
  1391. spMatchStatus = CreateNodeWithText(_bstrMatch, _bstrNotConfigured);
  1392. break;
  1393. default:
  1394. spMatchStatus = CreateNodeWithText(_bstrMatch, _bstrError);
  1395. break;
  1396. }
  1397. hr = spAnalysisResult->appendChild(spMatchStatus, NULL);
  1398. CheckAppendChildResult(hr);
  1399. hr = spAnalysisResult->appendChild(spnBaseline, NULL);
  1400. CheckAppendChildResult(hr);
  1401. hr = spAnalysisResult->appendChild(spnSystem, NULL);
  1402. CheckAppendChildResult(hr);
  1403. //
  1404. // append Analysis Result
  1405. //
  1406. hr = spSetting->appendChild(spAnalysisResult, NULL);
  1407. CheckAppendChildResult(hr);
  1408. //
  1409. // attach Setting to XML doc
  1410. //
  1411. hr = spCurrentArea->appendChild(spSetting, NULL);
  1412. CheckAppendChildResult(hr);
  1413. } catch (SceLogException *e) {
  1414. e->AddDebugInfo(L"SceXMLLogWriter::AddSetting(BSTR, BSTR, SXMATCH_STATUS. IXMLDOMNode*, IXMLDOMNode*");
  1415. throw e;
  1416. } catch (...) {
  1417. throw new SceLogException(SceLogException::SXERROR_INTERNAL,
  1418. L"SceXMLLogWriter::AddSetting(BSTR, BSTR, SXMATCH_STATUS. IXMLDOMNode*, IXMLDOMNode*",
  1419. NULL,
  1420. 0);
  1421. }
  1422. }
  1423. void
  1424. SceXMLLogWriter::CheckCreateNodeResult (
  1425. IN HRESULT hr
  1426. )
  1427. /*++
  1428. Routine Description:
  1429. Checks the HRESULT returned by IXMLDOMDocument->createNode
  1430. and throws the appropriate SceLogException if not S_OK
  1431. Arguments:
  1432. hr: HRESULT to check
  1433. Return Value:
  1434. none
  1435. Throws:
  1436. SceLogException*
  1437. --*/
  1438. {
  1439. if (FAILED(hr)) {
  1440. if (hr==E_INVALIDARG) {
  1441. throw new SceLogException(SceLogException::SXERROR_INTERNAL,
  1442. L"Invalid argument to IXMLDOMDocument->createNode",
  1443. NULL,
  1444. hr);
  1445. } else {
  1446. throw new SceLogException(SceLogException::SXERROR_INTERNAL,
  1447. L"IXMLDOMDOcument->createNode",
  1448. NULL,
  1449. hr);
  1450. }
  1451. }
  1452. }
  1453. void
  1454. SceXMLLogWriter::CheckAppendChildResult (
  1455. IN HRESULT hr
  1456. )
  1457. /*++
  1458. Routine Description:
  1459. Checks the HRESULT returned by IXMLDOMDocument->createNode
  1460. and throws the appropriate SceLogException if not S_OK
  1461. Arguments:
  1462. hr: HRESULT to check
  1463. Return Value:
  1464. none
  1465. Throws:
  1466. SceLogException*
  1467. --*/
  1468. {
  1469. if (FAILED(hr)) {
  1470. if (hr==E_INVALIDARG) {
  1471. throw new SceLogException(SceLogException::SXERROR_INTERNAL,
  1472. L"Invalid argument to IXMLDOMDocument->appendChild",
  1473. NULL,
  1474. hr);
  1475. } else {
  1476. throw new SceLogException(SceLogException::SXERROR_INTERNAL,
  1477. L"IXMLDOMDOcument->appendChild",
  1478. NULL,
  1479. hr);
  1480. }
  1481. }
  1482. }
  1483. void
  1484. SceXMLLogWriter::CheckCreatedCComBSTR(
  1485. IN CComBSTR bstrIn
  1486. )
  1487. /*++
  1488. Routine Description:
  1489. Throws a SceLogException if bstrIn was not successfully
  1490. allocated or is NULL
  1491. Arguments:
  1492. bstrIn: CComBSTR to check
  1493. Retrun Value:
  1494. none
  1495. Throws:
  1496. SceLogException*
  1497. --*/
  1498. {
  1499. if (bstrIn.m_str==NULL) {
  1500. throw new SceLogException(SceLogException::SXERROR_INTERNAL,
  1501. L"CComBSTR()",
  1502. NULL,
  1503. 0);
  1504. }
  1505. }