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.

239 lines
5.3 KiB

  1. //+----------------------------------------------------------------------------
  2. //
  3. // Windows NT Secure Server Roles Security Configuration Wizard
  4. //
  5. // Microsoft Windows
  6. // Copyright (C) Microsoft Corporation, 1992 - 2002
  7. //
  8. // File: state.cxx
  9. //
  10. // Contents: Wizard state object definition.
  11. //
  12. // History: 4-Oct-01 EricB created
  13. //
  14. //-----------------------------------------------------------------------------
  15. #include "pch.h"
  16. #include "resource.h"
  17. #include "misc.h"
  18. #include "state.h"
  19. static State* stateInstance;
  20. State::State() :
  21. _fNeedsCommandLineHelp(false),
  22. _InputType(CreateNew),
  23. _strInputFile(),
  24. _NumRoles(0)
  25. {
  26. RegistryKey keyDefFile;
  27. if (SUCCEEDED(keyDefFile.Open(HKEY_LOCAL_MACHINE,
  28. L"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\SSR")))
  29. {
  30. if (SUCCEEDED(keyDefFile.GetValue(L"MainXml", _strInputFile)))
  31. {
  32. LOG(String::format(L"Main XML input file is %1", _strInputFile.c_str()));
  33. }
  34. }
  35. }
  36. void
  37. State::Init()
  38. {
  39. ASSERT(!stateInstance);
  40. stateInstance = new State;
  41. }
  42. void
  43. State::Destroy()
  44. {
  45. delete stateInstance;
  46. };
  47. State&
  48. State::GetInstance()
  49. {
  50. ASSERT(stateInstance);
  51. return *stateInstance;
  52. }
  53. void
  54. State::SetInputFileName(String & strName)
  55. {
  56. ASSERT(!strName.empty());
  57. _strInputFile = strName;
  58. }
  59. //+----------------------------------------------------------------------------
  60. //
  61. // Method: State::ParseInputFile
  62. //
  63. // Loads the main.xml input file and parses it.
  64. //
  65. //-----------------------------------------------------------------------------
  66. HRESULT
  67. State::ParseInputFile(void)
  68. {
  69. LOG_FUNCTION(State::ParseInputFile);
  70. HRESULT hr = S_OK;
  71. SmartInterface<IXMLDOMDocument> siXmlMain;
  72. hr = siXmlMain.AcquireViaCreateInstance(CLSID_DOMDocument, NULL, CLSCTX_SERVER);
  73. if (FAILED(hr))
  74. {
  75. LOG(String::format(L"Creation of CLSID_DOMDocument failed with error %1!x!", hr));
  76. return hr;
  77. }
  78. VARIANT varInput;
  79. AutoBstr bstr(_strInputFile);
  80. VariantInit(&varInput);
  81. varInput.bstrVal = bstr;
  82. varInput.vt = VT_BSTR;
  83. VARIANT_BOOL fSuccess;
  84. hr = siXmlMain->load(varInput, &fSuccess);
  85. if (fSuccess == VARIANT_FALSE)
  86. {
  87. LOG(String::format(L"Load of %1 failed",
  88. _strInputFile.c_str()));
  89. return HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND);
  90. }
  91. if (FAILED(hr))
  92. {
  93. LOG(String::format(L"Load of %1 failed with error %2!x!",
  94. _strInputFile.c_str(), hr));
  95. return hr;
  96. }
  97. LOG(String::format(L"Load of %1 succeeded", _strInputFile.c_str()));
  98. IXMLDOMNode * pSSRNode = NULL, * pRolesNode = NULL;
  99. hr = siXmlMain->selectSingleNode(CComBSTR(g_wzSSRUIData), &pSSRNode);
  100. if (FAILED(hr) || !pSSRNode)
  101. {
  102. LOG(String::format(L"Select of SSRUIData Node in %1 failed with error %2!x!",
  103. _strInputFile.c_str(), hr));
  104. return hr;
  105. }
  106. _siXmlMainNode.Acquire(pSSRNode);
  107. hr = pSSRNode->selectSingleNode(CComBSTR(g_wzRoles), &pRolesNode);
  108. if (FAILED(hr) || !pRolesNode)
  109. {
  110. LOG(String::format(L"Select of Roles Node in %1 failed with error %2!x!",
  111. _strInputFile.c_str(), hr));
  112. return hr;
  113. }
  114. IXMLDOMNodeList * pList = NULL;
  115. hr = pRolesNode->selectNodes(CComBSTR(g_wzRole), &pList);
  116. if (FAILED(hr))
  117. {
  118. LOG(String::format(L"Search for Role Nodes in %1 failed with error %2!x!",
  119. _strInputFile.c_str(), hr));
  120. return hr;
  121. }
  122. _siXmlRoleNodeList.Acquire(pList);
  123. pRolesNode->Release();
  124. hr = _siXmlRoleNodeList->get_length(&_NumRoles);
  125. if (FAILED(hr))
  126. {
  127. LOG(String::format(L"Calling get_length on the Role Node list failed with error %1!x!",
  128. hr));
  129. return hr;
  130. }
  131. LOG(String::format(L"Number of Role nodes is %1!d!", _NumRoles));
  132. return hr;
  133. }
  134. //+----------------------------------------------------------------------------
  135. //
  136. // Method: State::GetRole
  137. //
  138. // Returns the role object for the indicated role.
  139. //
  140. //-----------------------------------------------------------------------------
  141. HRESULT
  142. State::GetRole(long index, RoleObject ** ppRole)
  143. {
  144. LOG_FUNCTION(State::GetRole);
  145. if (GetNumRoles() == 0)
  146. {
  147. ASSERT(false);
  148. return E_FAIL;
  149. }
  150. if (GetNumRoles() <= index || IsBadWritePtr(ppRole, sizeof(RoleObject *)))
  151. {
  152. ASSERT(false);
  153. return E_INVALIDARG;
  154. }
  155. HRESULT hr = S_OK;
  156. IXMLDOMNode * pRoleNode = NULL;
  157. hr = _siXmlRoleNodeList->get_item(index, &pRoleNode);
  158. if (FAILED(hr))
  159. {
  160. LOG(String::format(L"Getting role node %1!d! failed with error %1!x!",
  161. index, hr));
  162. return hr;
  163. }
  164. *ppRole = new RoleObject;
  165. if (!*ppRole)
  166. {
  167. pRoleNode->Release();
  168. return E_OUTOFMEMORY;
  169. }
  170. hr = (*ppRole)->InitFromXmlNode(pRoleNode);
  171. pRoleNode->Release();
  172. if (SUCCEEDED(hr))
  173. {
  174. hr = (*ppRole)->SetLocalizedNames(_siXmlMainNode);
  175. }
  176. return hr;
  177. }
  178. //+----------------------------------------------------------------------------
  179. //
  180. // Method: State::DoRollback
  181. //
  182. //
  183. //
  184. //-----------------------------------------------------------------------------
  185. HRESULT
  186. State::DoRollback(void)
  187. {
  188. LOG_FUNCTION(State::DoRollback);
  189. HRESULT hr = S_OK;
  190. return hr;
  191. }