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.

237 lines
6.2 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: RoleObj.cxx
  9. //
  10. // History: 15-Oct-01 Yanggao created
  11. //
  12. //-----------------------------------------------------------------------------
  13. #include "pch.h"
  14. #include "RoleObj.h"
  15. #include "misc.h"
  16. ////////////////////////////////////////////////////////////////////////////////
  17. //
  18. //
  19. ////////////////////////////////////////////////////////////////////////////////
  20. RoleObject::RoleObject(String& xmlroleName) :
  21. satisfiable(false),
  22. selected(false)
  23. {
  24. roleName = xmlroleName;
  25. }
  26. RoleObject::RoleObject(void) :
  27. satisfiable(false),
  28. selected(false)
  29. {
  30. }
  31. ////////////////////////////////////////////////////////////////////////////////
  32. //
  33. //
  34. ////////////////////////////////////////////////////////////////////////////////
  35. RoleObject::~RoleObject()
  36. {
  37. LOG_DTOR(RoleObject);
  38. SERVICELIST::iterator i;
  39. for(i=servicesList.begin(); i!=servicesList.end(); i++)
  40. {
  41. servicesList.erase(i);
  42. }
  43. }
  44. ////////////////////////////////////////////////////////////////////////////////
  45. //
  46. //
  47. ////////////////////////////////////////////////////////////////////////////////
  48. bool RoleObject::addService(ServiceObject* pobj)
  49. {
  50. servicesList.push_back(pobj);
  51. return true;
  52. }
  53. ////////////////////////////////////////////////////////////////////////////////
  54. //
  55. //
  56. ////////////////////////////////////////////////////////////////////////////////
  57. bool RoleObject::removeService(String str)
  58. {
  59. SERVICELIST::iterator i = servicesList.begin();
  60. for(i=servicesList.begin(); i!=servicesList.end(); i++)
  61. {
  62. if(((ServiceObject*)(*i))->serviceName.icompare(str) == 0)
  63. {
  64. servicesList.erase(i);
  65. return true;
  66. }
  67. }
  68. return false;
  69. }
  70. ////////////////////////////////////////////////////////////////////////////////
  71. //
  72. //
  73. ////////////////////////////////////////////////////////////////////////////////
  74. ServiceObject* RoleObject::findService(String str)
  75. {
  76. SERVICELIST::iterator i = servicesList.begin();
  77. for(i=servicesList.begin(); i!=servicesList.end(); i++)
  78. {
  79. if(((ServiceObject*)(*i))->serviceName.icompare(str) == 0)
  80. {
  81. return (*i);
  82. }
  83. }
  84. return NULL;
  85. }
  86. ////////////////////////////////////////////////////////////////////////////////
  87. //
  88. //
  89. ////////////////////////////////////////////////////////////////////////////////
  90. DWORD RoleObject::getServiceCount()
  91. {
  92. return (DWORD)servicesList.size();
  93. }
  94. //+----------------------------------------------------------------------------
  95. //
  96. // Method: RoleObject::getDisplayName
  97. //
  98. // If set, return the display name. Otherwise return the internal name.
  99. //
  100. //-----------------------------------------------------------------------------
  101. PCWSTR
  102. RoleObject::getDisplayName(void)
  103. {
  104. return _strRoleDisplayName.empty() ?
  105. roleName.c_str() : _strRoleDisplayName.c_str();
  106. }
  107. //+----------------------------------------------------------------------------
  108. //
  109. // Method: RoleObject::InitFromXmlNode
  110. //
  111. // Initialize the object from its main.xml node.
  112. //
  113. //-----------------------------------------------------------------------------
  114. HRESULT
  115. RoleObject::InitFromXmlNode(IXMLDOMNode * pRoleNode)
  116. {
  117. LOG_FUNCTION(RoleObject::InitFromXmlNode);
  118. HRESULT hr = S_OK;
  119. hr = GetNodeText(pRoleNode, g_wzName, roleName);
  120. if (FAILED(hr) || S_FALSE == hr)
  121. {
  122. LOG(String::format(L"Getting role name failed with error %1!x!", hr));
  123. return hr;
  124. }
  125. LOG(String::format(L"Role name is '%1'", roleName.c_str()));
  126. return hr;
  127. }
  128. //+----------------------------------------------------------------------------
  129. //
  130. // Method: RoleObject::InitFromXmlNode
  131. //
  132. // Initialize the object from its main.xml node.
  133. //
  134. //-----------------------------------------------------------------------------
  135. HRESULT
  136. RoleObject::SetLocalizedNames(IXMLDOMNode * pSSRNode)
  137. {
  138. LOG_FUNCTION(RoleObject::SetLocalizedNames);
  139. if (roleName.empty())
  140. {
  141. ASSERT(FALSE);
  142. return E_FAIL;
  143. }
  144. HRESULT hr = S_OK;
  145. IXMLDOMNode * pRoleLocNode = NULL;
  146. hr = pSSRNode->selectSingleNode(CComBSTR(g_wzRoleLocalization), &pRoleLocNode);
  147. if (FAILED(hr))
  148. {
  149. LOG(String::format(L"Select of RoleLocalization node failed with error %1!x!", hr));
  150. return hr;
  151. }
  152. ASSERT(pRoleLocNode);
  153. IXMLDOMNodeList * pRoleList = NULL;
  154. hr = pRoleLocNode->selectNodes(CComBSTR(g_wzRole), &pRoleList);
  155. pRoleLocNode->Release();
  156. if (FAILED(hr))
  157. {
  158. LOG(String::format(L"Select of RoleLocalization child nodes failed with error %1!x!", hr));
  159. return hr;
  160. }
  161. ASSERT(pRoleList);
  162. long nRoleNodes = 0;
  163. hr = pRoleList->get_length(&nRoleNodes);
  164. if (FAILED(hr))
  165. {
  166. LOG(String::format(L"Getting the size of the RoleLocalization Node list failed with error %1!x!", hr));
  167. return hr;
  168. }
  169. IXMLDOMNode * pRole;
  170. for (long i = 0; i < nRoleNodes; i++)
  171. {
  172. pRole = NULL;
  173. hr = pRoleList->get_item(i, &pRole);
  174. if (FAILED(hr))
  175. {
  176. LOG(String::format(L"Getting a RoleLocalization Node list item failed with error %1!x!", hr));
  177. pRoleList->Release();
  178. return hr;
  179. }
  180. ASSERT(pRole);
  181. String strName;
  182. hr = GetNodeText(pRole, g_wzName, strName);
  183. if (FAILED(hr))
  184. {
  185. LOG(String::format(L"Getting a RoleLocalization Node list item name failed with error %1!x!", hr));
  186. pRoleList->Release();
  187. return hr;
  188. }
  189. if (strName.icompare(roleName) == 0)
  190. {
  191. // Found the right one.
  192. //
  193. GetNodeText(pRole, g_wzDisplayName, _strRoleDisplayName);
  194. GetNodeText(pRole, g_wzDescription, roleDescription);
  195. pRole->Release();
  196. pRoleList->Release();
  197. return S_OK;
  198. }
  199. pRole->Release();
  200. }
  201. pRoleList->Release();
  202. LOG(String::format(L"Did not find the RoleLocalization Node item for role %1", roleName.c_str()));
  203. return S_FALSE;
  204. }