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.

438 lines
10 KiB

  1. /*++
  2. Copyright (c) 1999-2001 Microsoft Corporation
  3. Module Name:
  4. roletask.cpp
  5. Abstract:
  6. This module implements routines for role/task
  7. specific SSR Knowledge Base processing.
  8. Author:
  9. Vishnu Patankar (VishnuP) - Oct 2001
  10. Environment:
  11. User mode only.
  12. Exported Functions:
  13. Revision History:
  14. Created - Oct 2001
  15. --*/
  16. #include "stdafx.h"
  17. #include "kbproc.h"
  18. #include "process.h"
  19. HRESULT
  20. process::SsrpProcessRolesOrTasks(
  21. IN PWSTR pszMachineName,
  22. IN CComPtr<IXMLDOMElement> pXMLDocElemRoot,
  23. IN CComPtr<IXMLDOMDocument> pXMLDoc,
  24. IN PWSTR pszKbMode,
  25. IN BOOL bRole
  26. )
  27. /*++
  28. Routine Description:
  29. Routine called to process all roles
  30. Arguments:
  31. pszMachineName - name of machine to preprocess
  32. pXMLDocElemRoot - root of document
  33. pXMLDoc - KB document
  34. pszKbMode - mode value
  35. Return:
  36. HRESULT error code
  37. ++*/
  38. {
  39. HRESULT hr = S_OK;
  40. DWORD rc;
  41. ULONG uRoleIndex = 0;
  42. ULONG uServiceIndex = 0;
  43. CComPtr<IXMLDOMNodeList> pResultList;
  44. CComPtr<IXMLDOMNode> pXMLRoleOrTaskNode;
  45. CComPtr<IXMLDOMNodeList> pChildList;
  46. CComVariant Type(NODE_ELEMENT);
  47. //
  48. // get the "Role" or "Task" node
  49. //
  50. hr = pXMLDocElemRoot->selectNodes(bRole ? L"Roles/Role" : L"Tasks/Task", &pResultList);
  51. if (FAILED(hr) || pResultList == NULL ) {
  52. SsrpLogParseError(hr);
  53. goto ExitHandler;
  54. }
  55. hr = pResultList->get_item( uRoleIndex, &pXMLRoleOrTaskNode);
  56. if (FAILED(hr) || pXMLRoleOrTaskNode == NULL ) {
  57. SsrpLogParseError(hr);
  58. goto ExitHandler;
  59. }
  60. //
  61. // for each Role
  62. //
  63. while ( pXMLRoleOrTaskNode != NULL) {
  64. BOOL bRoleIsSatisfiable = TRUE;
  65. BOOL bSomeRequiredServiceDisabled = FALSE;
  66. CComBSTR bstrRoleName;
  67. CComPtr<IXMLDOMNode> pNameNode;
  68. CComPtr<IXMLDOMNode> pXMLRoleModeNode;
  69. CComPtr<IXMLDOMNode> pXMLRoleSelectedNode;
  70. CComPtr<IXMLDOMNode> pXMLValueNode;
  71. CComPtr<IXMLDOMNode> pXMLServiceNode;
  72. CComPtr<IXMLDOMNamedNodeMap> pXMLAttribNode;
  73. hr = pXMLRoleOrTaskNode->selectSingleNode(L"Name", &pNameNode );
  74. if (FAILED(hr) || pNameNode == NULL){
  75. SsrpLogParseError(hr);
  76. goto ExitHandler;
  77. }
  78. pNameNode->get_text(&bstrRoleName);
  79. if (FAILED(hr) || !bstrRoleName){
  80. SsrpLogParseError(hr);
  81. goto ExitHandler;
  82. }
  83. hr = pXMLRoleOrTaskNode->selectSingleNode( L"Selected", &pXMLRoleSelectedNode );
  84. if (FAILED(hr) || pXMLRoleSelectedNode == NULL){
  85. SsrpLogParseError(hr);
  86. goto ExitHandler;
  87. }
  88. hr = pXMLRoleSelectedNode->selectSingleNode(pszKbMode, &pXMLRoleModeNode );
  89. if (FAILED(hr) || pXMLRoleModeNode == NULL){
  90. SsrpLogParseError(hr);
  91. goto ExitHandler;
  92. }
  93. hr = pXMLRoleModeNode->get_attributes( &pXMLAttribNode );
  94. if (FAILED(hr) || pXMLAttribNode == NULL){
  95. SsrpLogParseError(hr);
  96. goto ExitHandler;
  97. }
  98. hr = pXMLAttribNode->getNamedItem(L"Value", &pXMLValueNode );
  99. if (FAILED(hr) || pXMLValueNode == NULL){
  100. SsrpLogParseError(hr);
  101. goto ExitHandler;
  102. }
  103. CComBSTR bstrModeValue;
  104. hr = pXMLValueNode->get_text(&bstrModeValue);
  105. if (FAILED(hr) || !bstrModeValue){
  106. SsrpLogParseError(hr);
  107. goto ExitHandler;
  108. }
  109. hr = SsrpDeleteChildren(pXMLRoleSelectedNode);
  110. if (FAILED(hr) ){
  111. SsrpLogParseError(hr);
  112. goto ExitHandler;
  113. }
  114. CComPtr <IXMLDOMNodeList> pServiceList;
  115. hr = pXMLRoleOrTaskNode->selectNodes(L"Services/Service", &pServiceList);
  116. if (FAILED(hr) || pServiceList == NULL){
  117. SsrpLogParseError(hr);
  118. goto ExitHandler;
  119. }
  120. uServiceIndex=0;
  121. hr = pServiceList->get_item( uServiceIndex, &pXMLServiceNode);
  122. if (FAILED(hr) || pXMLServiceNode == NULL ) {
  123. SsrpLogParseError(hr);
  124. goto ExitHandler;
  125. }
  126. //
  127. // for each Service
  128. //
  129. while ( pXMLServiceNode != NULL) {
  130. hr = SsrpProcessService(pXMLDocElemRoot,
  131. pXMLServiceNode,
  132. pszKbMode,
  133. &bRoleIsSatisfiable,
  134. &bSomeRequiredServiceDisabled);
  135. if (FAILED(hr)) {
  136. SsrpLogParseError(hr);
  137. goto ExitHandler;
  138. }
  139. pXMLServiceNode.Release();
  140. uServiceIndex++;
  141. hr = pServiceList->get_item( uServiceIndex, &pXMLServiceNode);
  142. if (FAILED(hr)){
  143. SsrpLogParseError(hr);
  144. goto ExitHandler;
  145. }
  146. }
  147. BOOL bRoleSelect = FALSE;
  148. if (bRoleIsSatisfiable) {
  149. if (0 == SsrpICompareBstrPwstr(bstrModeValue, L"TRUE")){
  150. bRoleSelect = TRUE;
  151. }
  152. else if (0 == SsrpICompareBstrPwstr(bstrModeValue, L"DEFAULT")){
  153. bRoleSelect = !bSomeRequiredServiceDisabled;
  154. }
  155. else if (0 == SsrpICompareBstrPwstr(bstrModeValue, L"CUSTOM")){
  156. //
  157. // get the attributes "FunctionName" and "DLLName"
  158. //
  159. CComBSTR bstrFunctionName;
  160. CComBSTR bstrDLLName;
  161. CComPtr <IXMLDOMNode> pXMLFunctionName;
  162. CComPtr <IXMLDOMNode> pXMLDLLName;
  163. hr = pXMLAttribNode->getNamedItem(L"FunctionName", &pXMLFunctionName );
  164. if (FAILED(hr) || pXMLFunctionName == NULL){
  165. SsrpLogParseError(hr);
  166. goto ExitHandler;
  167. }
  168. hr = pXMLFunctionName->get_text(&bstrFunctionName);
  169. if (FAILED(hr) || !bstrFunctionName){
  170. SsrpLogParseError(hr);
  171. goto ExitHandler;
  172. }
  173. hr = pXMLAttribNode->getNamedItem(L"DLLName", &pXMLDLLName );
  174. if (FAILED(hr) || pXMLDLLName == NULL){
  175. SsrpLogParseError(hr);
  176. goto ExitHandler;
  177. }
  178. hr = pXMLDLLName->get_text(&bstrDLLName);
  179. if (FAILED(hr) || !bstrDLLName){
  180. SsrpLogParseError(hr);
  181. goto ExitHandler;
  182. }
  183. rc = SsrpEvaluateCustomFunction(pszMachineName, bstrDLLName, bstrFunctionName, &bRoleSelect);
  184. if (rc != ERROR_SUCCESS) {
  185. WCHAR szMsg[MAX_PATH];
  186. swprintf(szMsg, L"%s not found", bstrFunctionName);
  187. SsrpLogError(szMsg);
  188. // SsrpLogWin32Error(rc);
  189. // continue on error
  190. // goto ExitHandler;
  191. }
  192. }
  193. }
  194. hr = pXMLRoleSelectedNode->put_text(bRoleSelect ? L"TRUE" : L"FALSE");
  195. if (FAILED(hr)) {
  196. SsrpLogParseError(hr);
  197. goto ExitHandler;
  198. }
  199. CComPtr <IXMLDOMNode> pFirstChild;
  200. CComPtr <IXMLDOMNode> pNextSibling;
  201. hr = pXMLRoleOrTaskNode->get_firstChild(&pFirstChild);
  202. if (FAILED(hr) || pFirstChild == NULL) {
  203. SsrpLogParseError(hr);
  204. goto ExitHandler;
  205. }
  206. hr = pFirstChild->get_nextSibling(&pNextSibling);
  207. if (FAILED(hr) || pNextSibling == NULL) {
  208. SsrpLogParseError(hr);
  209. goto ExitHandler;
  210. }
  211. CComVariant vtRefChild(pNextSibling);
  212. CComPtr<IXMLDOMNode> pXDNodeCreate;
  213. hr = pXMLDoc->createNode(
  214. Type,
  215. L"Satisfiable",
  216. NULL,
  217. &pXDNodeCreate);
  218. if (FAILED(hr) || pXDNodeCreate == NULL) {
  219. SsrpLogParseError(hr);
  220. goto ExitHandler;
  221. }
  222. hr = pXDNodeCreate->put_text(bRoleIsSatisfiable ? L"TRUE" : L"FALSE");
  223. if (m_bDbg) {
  224. if (bRoleIsSatisfiable)
  225. wprintf(L"ROLE satisfiable: %s\n", bstrRoleName);
  226. else
  227. wprintf(L"ROLE not satisfiable: %s\n", bstrRoleName);
  228. }
  229. if (FAILED(hr)) {
  230. SsrpLogParseError(hr);
  231. goto ExitHandler;
  232. }
  233. hr = pXMLRoleOrTaskNode->insertBefore(pXDNodeCreate,
  234. vtRefChild,
  235. NULL);
  236. if (FAILED(hr)) {
  237. SsrpLogParseError(hr);
  238. goto ExitHandler;
  239. }
  240. uRoleIndex++;
  241. pXMLRoleOrTaskNode.Release();
  242. hr = pResultList->get_item( uRoleIndex, &pXMLRoleOrTaskNode);
  243. if (FAILED(hr)){
  244. SsrpLogParseError(hr);
  245. goto ExitHandler;
  246. }
  247. }
  248. ExitHandler:
  249. return hr;
  250. }
  251. #if 0
  252. HRESULT
  253. process::SsrpAddUnknownSection(
  254. IN CComPtr <IXMLDOMElement> pXMLDocElemRoot,
  255. IN CComPtr <IXMLDOMDocument> pXMLDoc
  256. )
  257. /*++
  258. Routine Description:
  259. Routine called to add the "Unknown" section
  260. Arguments:
  261. pXMLDocElemRoot - root of document
  262. pXMLDoc - KB document
  263. Return:
  264. HRESULT error code
  265. ++*/
  266. {
  267. HRESULT hr;
  268. CComPtr <IXMLDOMNode> pUnknownNode;
  269. hr = pXMLDocElemRoot->selectSingleNode(L"Roles", &pRolesNode);
  270. if (FAILED(hr) || pRolesNode == NULL ) {
  271. SsrpLogParseError(hr);
  272. goto ExitHandler;
  273. }
  274. hr = SsrpAddExtraServices(pXMLDoc, pRolesNode);
  275. if (FAILED(hr)) {
  276. SsrpLogParseError(hr);
  277. goto ExitHandler;
  278. }
  279. ExitHandler:
  280. return hr;
  281. }
  282. #endif