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.

3010 lines
95 KiB

  1. /*****************************************************************************
  2. Copyright information : Copyright (c) 1998-1999 Microsoft Corporation
  3. File Name : CmdAlias.cpp
  4. Project Name : WMI Command Line
  5. Author Name : Ch. Sriramachandramurthy
  6. Date of Creation (dd/mm/yy) : 27th-September-2000
  7. Version Number : 1.0
  8. Brief Description : The CmdAlias class encapsulates the
  9. functionality for retrieving alias information.
  10. Revision History :
  11. Last Modified By : C V Nandi
  12. Last Modified Date : 16th-March-2001
  13. *****************************************************************************/
  14. #include "Precomp.h"
  15. #include "GlobalSwitches.h"
  16. #include "CommandSwitches.h"
  17. #include "HelpInfo.h"
  18. #include "ErrorLog.h"
  19. #include "ParsedInfo.h"
  20. #include "CmdAlias.h"
  21. #include "CmdTokenizer.h"
  22. #include "ErrorInfo.h"
  23. #include "WMICliXMLLog.h"
  24. #include "ParserEngine.h"
  25. #include "ExecEngine.h"
  26. #include "FormatEngine.h"
  27. #include "WmiCmdLn.h"
  28. /*----------------------------------------------------------------------------
  29. Name :CCmdAlias
  30. Synopsis :This function initializes the member variables when an
  31. object of the class type is instantiated.
  32. Type :Constructor
  33. Input parameter :None
  34. Output parameters :None
  35. Return Type :None
  36. Global Variables :None
  37. Calling Syntax :None
  38. Notes :None
  39. ----------------------------------------------------------------------------*/
  40. CCmdAlias::CCmdAlias()
  41. {
  42. m_pIAliasNS = NULL;
  43. m_pILocalizedNS = NULL;
  44. m_bTrace = FALSE;
  45. m_eloErrLogOpt = NO_LOGGING;
  46. }
  47. /*----------------------------------------------------------------------------
  48. Name :~CCmdAlias
  49. Synopsis :This function uninitializes the member variables when an
  50. object of the class type goes out of scope.
  51. Type :Destructor
  52. Input parameter :None
  53. Output parameters :None
  54. Return Type :None
  55. Global Variables :None
  56. Calling Syntax :None
  57. Notes :None
  58. ----------------------------------------------------------------------------*/
  59. CCmdAlias::~CCmdAlias()
  60. {
  61. SAFEIRELEASE(m_pIAliasNS);
  62. SAFEIRELEASE(m_pILocalizedNS);
  63. }
  64. /*----------------------------------------------------------------------------
  65. Name :Uninitialize
  66. Synopsis :This function uninitializes the member variables when
  67. the execution of a command string issued on the command
  68. line is completed.
  69. Type :Member Function
  70. Input Parameter(s):
  71. bFinal - boolean value which when set indicates that the program
  72. Output parameters :None
  73. Return Type :None
  74. Global Variables :None
  75. Calling Syntax :Uninitialize(bFinal)
  76. Notes :None
  77. ----------------------------------------------------------------------------*/
  78. void CCmdAlias::Uninitialize(BOOL bFinal)
  79. {
  80. m_bTrace = FALSE;
  81. // If end of program
  82. if (bFinal)
  83. {
  84. SAFEIRELEASE(m_pILocalizedNS);
  85. SAFEIRELEASE(m_pIAliasNS);
  86. }
  87. }
  88. /*----------------------------------------------------------------------------
  89. Name :ConnectToAlias
  90. Synopsis :This function connects to WMI namespace on the specified
  91. machine using the information available CParsedInfo
  92. class object.
  93. Type :Member Function
  94. Input parameter(s):
  95. rParsedInfo - reference to CParsedInfo class object.
  96. pIWbemLocator - IWbemLocator object for connecting to WMI .
  97. Output parameter(s):
  98. rParsedInfo - reference to CParsedInfo class object.
  99. Return Type :HRESULT
  100. Global Variables :None
  101. Calling Syntax :ConnectToAlias(rParsedInfo,pIWbemLocator)
  102. Notes :None
  103. ----------------------------------------------------------------------------*/
  104. HRESULT CCmdAlias::ConnectToAlias(CParsedInfo& rParsedInfo,
  105. IWbemLocator* pIWbemLocator)
  106. {
  107. // Get current thread for logging the success or failure of the command.
  108. DWORD dwThreadId = GetCurrentThreadId();
  109. HRESULT hr = S_OK;
  110. // Set the trace flag
  111. m_bTrace = rParsedInfo.GetGlblSwitchesObject().GetTraceStatus();
  112. m_eloErrLogOpt = rParsedInfo.GetErrorLogObject().GetErrLogOption();
  113. try
  114. {
  115. // If the /ROLE has been changed since last invocation
  116. if (rParsedInfo.GetGlblSwitchesObject().GetRoleFlag() == TRUE)
  117. {
  118. SAFEIRELEASE(m_pIAliasNS);
  119. CHString chsMsg;
  120. // Connect to the specified namespace of Windows Management on the
  121. // local computer using the locator object.
  122. hr = Connect(pIWbemLocator, &m_pIAliasNS,
  123. _bstr_t(rParsedInfo.GetGlblSwitchesObject().GetRole()),
  124. NULL, NULL, _bstr_t(rParsedInfo.GetGlblSwitchesObject().
  125. GetLocale()), rParsedInfo);
  126. // If /TRACE is ON
  127. if (m_bTrace || m_eloErrLogOpt)
  128. {
  129. chsMsg.Format(
  130. L"IWbemLocator::ConnectServer(L\"%s\", NULL, NULL, "
  131. L"L\"%s\", 0L, L\"%s\", NULL, -)",
  132. rParsedInfo.GetGlblSwitchesObject().GetRole(),
  133. rParsedInfo.GetGlblSwitchesObject().GetLocale(),
  134. (rParsedInfo.GetAuthorityPrinciple()) ?
  135. rParsedInfo.GetAuthorityPrinciple() : L"<null>");
  136. WMITRACEORERRORLOG(hr, __LINE__, __FILE__, (LPCWSTR)chsMsg,
  137. dwThreadId, rParsedInfo, m_bTrace);
  138. }
  139. ONFAILTHROWERROR(hr);
  140. // Set the interface level security
  141. hr =
  142. SetSecurity(m_pIAliasNS, NULL, NULL, NULL, NULL,
  143. rParsedInfo.GetGlblSwitchesObject().GetAuthenticationLevel(),
  144. rParsedInfo.GetGlblSwitchesObject().GetImpersonationLevel());
  145. // If /TRACE is ON
  146. if (m_bTrace || m_eloErrLogOpt)
  147. {
  148. chsMsg.Format(L"CoSetProxyBlanket(-, RPC_C_AUTHN_WINNT, "
  149. L"RPC_C_AUTHZ_NONE, NULL, %d, %d, -, EOAC_NONE)",
  150. rParsedInfo.GetGlblSwitchesObject().GetAuthenticationLevel(),
  151. rParsedInfo.GetGlblSwitchesObject().GetImpersonationLevel());
  152. WMITRACEORERRORLOG(hr, __LINE__, __FILE__, (LPCWSTR)chsMsg,
  153. dwThreadId, rParsedInfo, m_bTrace);
  154. }
  155. ONFAILTHROWERROR(hr);
  156. rParsedInfo.GetGlblSwitchesObject().SetRoleFlag(FALSE);
  157. }
  158. // Connect to the localized Namespace
  159. hr = ConnectToLocalizedNS(rParsedInfo, pIWbemLocator);
  160. ONFAILTHROWERROR(hr);
  161. }
  162. catch(_com_error& e)
  163. {
  164. // Set the COM error
  165. rParsedInfo.GetCmdSwitchesObject().SetCOMError(e);
  166. hr = e.Error();
  167. }
  168. catch(CHeap_Exception)
  169. {
  170. hr = WBEM_E_OUT_OF_MEMORY;
  171. _com_issue_error(hr);
  172. }
  173. return hr;
  174. }
  175. /*----------------------------------------------------------------------------
  176. Name :ObtainAliasInfo
  177. Synopsis :Obtains the following info of the alias specified.
  178. 1. alias PWhere expression
  179. 2. alias target string
  180. 3. alias description
  181. from the alias definition and updates the information in
  182. the CParsedInfo object passed as reference.
  183. Type :Member Function
  184. Input parameter(s):
  185. rParsedInfo - The parsed info from command line input.
  186. Output parameter(s):
  187. rParsedInfo - The parsed info from command line input.
  188. Return Type :RETCODE
  189. Global Variables :None
  190. Calling Syntax :ObtainAliasInfo(rParsedInfo)
  191. Notes :None
  192. ----------------------------------------------------------------------------*/
  193. RETCODE CCmdAlias::ObtainAliasInfo(CParsedInfo& rParsedInfo)
  194. {
  195. // Variables being used in this function.
  196. IWbemClassObject *pIWbemObj = NULL;
  197. IUnknown *pIUnknown = NULL;
  198. IWbemClassObject *pIEmbedObj = NULL;
  199. HRESULT hr = S_OK;
  200. RETCODE retCode = PARSER_CONTINUE;
  201. DWORD dwThreadId = GetCurrentThreadId();
  202. // Variants to save the properties and also for the embedded objects.
  203. VARIANT vtProp, vtEmbedProp;
  204. VariantInit(&vtProp);
  205. VariantInit(&vtEmbedProp);
  206. try
  207. {
  208. _bstr_t bstrResult;
  209. CHString chsMsg;
  210. // Object path of the required alias.
  211. _bstr_t bstrPath = _bstr_t("MSFT_CliAlias.FriendlyName='") +
  212. _bstr_t(rParsedInfo.GetCmdSwitchesObject().
  213. GetAliasName()) + _bstr_t(L"'");
  214. //Retrieving the object from the namespace in m_pIAliasNS
  215. hr = m_pIAliasNS->GetObject(bstrPath, 0, NULL, &pIWbemObj, NULL);
  216. if (m_bTrace || m_eloErrLogOpt)
  217. {
  218. chsMsg.Format(L"IWbemServices::GetObject(L\"%s\", 0, NULL, -)",
  219. (WCHAR*) bstrPath);
  220. WMITRACEORERRORLOG(hr, __LINE__, __FILE__, (LPCWSTR)chsMsg,
  221. dwThreadId, rParsedInfo, m_bTrace);
  222. }
  223. // To set errata code that indicates a more user friendly error
  224. // message to the user.
  225. if ( FAILED ( hr ) )
  226. {
  227. // Don't set com error in catch block.
  228. rParsedInfo.GetCmdSwitchesObject().SetErrataCode(
  229. IDS_E_ALIAS_NOT_FOUND);
  230. }
  231. ONFAILTHROWERROR(hr);
  232. //1. Retrieve the value of 'Target' property object
  233. hr = pIWbemObj->Get(_bstr_t(L"Target"), 0, &vtProp, 0, 0 );
  234. if (m_bTrace || m_eloErrLogOpt)
  235. {
  236. chsMsg.Format(L"IWbemClassObject::Get(L\"Target\", 0, -, 0, 0)");
  237. GetBstrTFromVariant(vtProp, bstrResult);
  238. WMITRACEORERRORLOG(hr, __LINE__, __FILE__,
  239. (LPCWSTR)chsMsg, dwThreadId, rParsedInfo,
  240. m_bTrace, 0, bstrResult);
  241. }
  242. ONFAILTHROWERROR(hr);
  243. if (vtProp.vt != VT_NULL && vtProp.vt != VT_EMPTY)
  244. {
  245. if(!rParsedInfo.GetCmdSwitchesObject().SetAliasTarget(
  246. (_TCHAR*)vtProp.bstrVal))
  247. {
  248. rParsedInfo.GetCmdSwitchesObject().
  249. SetErrataCode(OUT_OF_MEMORY);
  250. retCode = PARSER_OUTOFMEMORY;
  251. }
  252. }
  253. if(retCode != PARSER_OUTOFMEMORY)
  254. {
  255. VARIANTCLEAR(vtProp);
  256. //2. Retrieve the value of 'PWhere' property object
  257. VariantInit(&vtProp);
  258. hr = pIWbemObj->Get(_bstr_t(L"PWhere"), 0, &vtProp, 0, 0);
  259. if (m_bTrace || m_eloErrLogOpt)
  260. {
  261. chsMsg.Format(L"IWbemClassObject::Get(L\"PWhere\", 0, -,"
  262. L"0, 0)");
  263. GetBstrTFromVariant(vtProp, bstrResult);
  264. WMITRACEORERRORLOG(hr, __LINE__, __FILE__, (LPCWSTR)chsMsg,
  265. dwThreadId, rParsedInfo, m_bTrace,
  266. 0, bstrResult);
  267. }
  268. ONFAILTHROWERROR(hr);
  269. if (vtProp.vt != VT_NULL && vtProp.vt != VT_EMPTY)
  270. {
  271. if(!rParsedInfo.GetCmdSwitchesObject().SetPWhereExpr(
  272. (_TCHAR*)vtProp.bstrVal))
  273. {
  274. rParsedInfo.GetCmdSwitchesObject().
  275. SetErrataCode(OUT_OF_MEMORY);
  276. retCode = PARSER_OUTOFMEMORY;
  277. }
  278. }
  279. if(retCode != PARSER_OUTOFMEMORY)
  280. {
  281. VARIANTCLEAR(vtProp);
  282. // Retrieve the "Connection" property value
  283. VariantInit(&vtProp);
  284. hr = pIWbemObj->Get(_bstr_t(L"Connection"), 0, &vtProp, 0, 0);
  285. if (m_bTrace || m_eloErrLogOpt)
  286. {
  287. chsMsg.Format(L"IWbemClassObject::Get(L\"Connection\","
  288. L"0, -, 0, 0)");
  289. GetBstrTFromVariant(vtProp, bstrResult);
  290. WMITRACEORERRORLOG(hr, __LINE__, __FILE__, (LPCWSTR)chsMsg,
  291. dwThreadId, rParsedInfo, m_bTrace,
  292. 0, bstrResult);
  293. }
  294. ONFAILTHROWERROR(hr);
  295. if (vtProp.vt != VT_NULL && vtProp.vt != VT_EMPTY)
  296. {
  297. pIUnknown = vtProp.punkVal;
  298. hr = pIUnknown->QueryInterface(IID_IWbemClassObject,
  299. (void**)&pIEmbedObj);
  300. if (m_bTrace || m_eloErrLogOpt)
  301. {
  302. chsMsg.Format(L"QueryInterface("
  303. L"IID_IWbemClassObject, -)");
  304. WMITRACEORERRORLOG(hr, __LINE__, __FILE__,
  305. (LPCWSTR)chsMsg, dwThreadId,
  306. rParsedInfo, m_bTrace);
  307. }
  308. ONFAILTHROWERROR(hr);
  309. retCode =
  310. ObtainAliasConnectionInfo(rParsedInfo, pIEmbedObj);
  311. //Releasing the embedded object.
  312. SAFEIRELEASE(pIEmbedObj);
  313. VARIANTCLEAR(vtProp);
  314. }
  315. }
  316. }
  317. // Obtain the alias description
  318. if (retCode != PARSER_OUTOFMEMORY)
  319. {
  320. _bstr_t bstrDesc;
  321. hr = GetDescOfObject(pIWbemObj, bstrDesc, rParsedInfo, TRUE);
  322. ONFAILTHROWERROR(hr);
  323. if(!rParsedInfo.GetCmdSwitchesObject().
  324. SetAliasDesc((_TCHAR*)bstrDesc))
  325. {
  326. rParsedInfo.GetCmdSwitchesObject().
  327. SetErrataCode(OUT_OF_MEMORY);
  328. retCode = PARSER_OUTOFMEMORY;
  329. }
  330. }
  331. SAFEIRELEASE(pIWbemObj);
  332. }
  333. catch(_com_error& e)
  334. {
  335. SAFEIRELEASE(pIWbemObj);
  336. SAFEIRELEASE(pIEmbedObj);
  337. VARIANTCLEAR(vtProp);
  338. VARIANTCLEAR(vtEmbedProp);
  339. // No errata code then set com error.
  340. if ( rParsedInfo.GetCmdSwitchesObject().GetErrataCode() == 0 )
  341. rParsedInfo.GetCmdSwitchesObject().SetCOMError(e);
  342. retCode = PARSER_ERRMSG;
  343. }
  344. catch(CHeap_Exception)
  345. {
  346. SAFEIRELEASE(pIWbemObj);
  347. SAFEIRELEASE(pIEmbedObj);
  348. VARIANTCLEAR(vtProp);
  349. VARIANTCLEAR(vtEmbedProp);
  350. retCode = PARSER_ERRMSG;
  351. hr = WBEM_E_OUT_OF_MEMORY;
  352. _com_issue_error(hr);
  353. }
  354. return retCode;
  355. }
  356. /*----------------------------------------------------------------------------
  357. Name :ObtainAliasConnectionInfo
  358. Synopsis : Obtain the alias connection information like
  359. 1. namespace 2. user 3. password
  360. 4. locale 5. server 6. authority
  361. Type :Member Function
  362. Input parameter(s):
  363. rParsedInfo - The parsed info from command line input.
  364. pIEmbedObj - Pointer to the IWbem class object
  365. Output parameter(s):
  366. rParsedInfo - The parsed info from command line input.
  367. Return Type :RETCODE
  368. Global Variables :None
  369. Calling Syntax :ObtainAliasConnectionInfo(rParsedInfo)
  370. Notes :None
  371. ----------------------------------------------------------------------------*/
  372. RETCODE CCmdAlias::ObtainAliasConnectionInfo(CParsedInfo& rParsedInfo,
  373. IWbemClassObject* pIEmbedObj)
  374. {
  375. RETCODE retCode = PARSER_CONTINUE;
  376. HRESULT hr = S_OK;
  377. UINT uConnFlag = 0;
  378. DWORD dwThreadId = GetCurrentThreadId();
  379. VARIANT vtEmbedProp;
  380. VariantInit(&vtEmbedProp);
  381. uConnFlag = rParsedInfo.GetGlblSwitchesObject().GetConnInfoFlag();
  382. try
  383. {
  384. CHString chsMsg;
  385. _bstr_t bstrResult;
  386. if (!(uConnFlag & NAMESPACE))
  387. {
  388. // retrieve the value of 'Namespace' property
  389. hr = pIEmbedObj->Get(_bstr_t(L"Namespace"), 0, &vtEmbedProp, 0,0);
  390. if (m_bTrace || m_eloErrLogOpt)
  391. {
  392. chsMsg.Format(L"IWbemClassObject::Get(L\"Namespace\", 0, -,"
  393. L"0, 0)");
  394. GetBstrTFromVariant(vtEmbedProp, bstrResult);
  395. WMITRACEORERRORLOG(hr, __LINE__, __FILE__, (LPCWSTR)chsMsg,
  396. dwThreadId, rParsedInfo, m_bTrace,
  397. 0, bstrResult);
  398. }
  399. ONFAILTHROWERROR(hr);
  400. if (vtEmbedProp.vt != VT_NULL && vtEmbedProp.vt != VT_EMPTY)
  401. {
  402. if(!rParsedInfo.GetCmdSwitchesObject().SetAliasNamespace(
  403. (_TCHAR*)vtEmbedProp.bstrVal))
  404. {
  405. rParsedInfo.GetCmdSwitchesObject().
  406. SetErrataCode(OUT_OF_MEMORY);
  407. retCode = PARSER_OUTOFMEMORY;
  408. }
  409. VARIANTCLEAR(vtEmbedProp);
  410. }
  411. }
  412. if(retCode != PARSER_OUTOFMEMORY)
  413. {
  414. if (!(uConnFlag & LOCALE))
  415. {
  416. // retrieve the value of 'Locale' property
  417. hr = pIEmbedObj->Get(_bstr_t(L"Locale"), 0, &vtEmbedProp,0,0);
  418. if (m_bTrace || m_eloErrLogOpt)
  419. {
  420. chsMsg.Format(L"IWbemClassObject::Get(L\"Locale\", 0,"
  421. L"-, 0, 0)");
  422. GetBstrTFromVariant(vtEmbedProp, bstrResult);
  423. WMITRACEORERRORLOG(hr, __LINE__, __FILE__,(LPCWSTR)chsMsg,
  424. dwThreadId, rParsedInfo, m_bTrace,
  425. 0, bstrResult);
  426. }
  427. ONFAILTHROWERROR(hr);
  428. if (vtEmbedProp.vt != VT_NULL && vtEmbedProp.vt != VT_EMPTY)
  429. {
  430. if(!rParsedInfo.GetCmdSwitchesObject().SetAliasLocale(
  431. (_TCHAR*)vtEmbedProp.bstrVal))
  432. {
  433. rParsedInfo.GetCmdSwitchesObject().
  434. SetErrataCode(OUT_OF_MEMORY);
  435. retCode = PARSER_OUTOFMEMORY;
  436. }
  437. VARIANTCLEAR(vtEmbedProp);
  438. }
  439. }
  440. if(retCode != PARSER_OUTOFMEMORY)
  441. {
  442. if (!(uConnFlag & USER))
  443. {
  444. // retrieve the value of 'User' property
  445. hr =
  446. pIEmbedObj->Get(_bstr_t(L"User"), 0, &vtEmbedProp, 0,0);
  447. if (m_bTrace || m_eloErrLogOpt)
  448. {
  449. chsMsg.Format(L"IWbemClassObject::Get(L\"User\", 0,"
  450. L"-, 0, 0)");
  451. GetBstrTFromVariant(vtEmbedProp, bstrResult);
  452. WMITRACEORERRORLOG( hr, __LINE__, __FILE__,
  453. (LPCWSTR)chsMsg, dwThreadId,
  454. rParsedInfo, m_bTrace,
  455. 0, bstrResult );
  456. }
  457. ONFAILTHROWERROR(hr);
  458. if (vtEmbedProp.vt != VT_NULL &&
  459. vtEmbedProp.vt != VT_EMPTY)
  460. {
  461. if(!rParsedInfo.GetCmdSwitchesObject().SetAliasUser(
  462. (_TCHAR*)vtEmbedProp.bstrVal))
  463. {
  464. rParsedInfo.GetCmdSwitchesObject().
  465. SetErrataCode(OUT_OF_MEMORY);
  466. retCode = PARSER_OUTOFMEMORY;
  467. }
  468. VARIANTCLEAR(vtEmbedProp);
  469. }
  470. }
  471. if(retCode != PARSER_OUTOFMEMORY)
  472. {
  473. if (!(uConnFlag & PASSWORD))
  474. {
  475. // retrieve the value of 'Password' property
  476. hr = pIEmbedObj->Get(_bstr_t(L"Password"),
  477. 0, &vtEmbedProp, 0,0);
  478. if (m_bTrace || m_eloErrLogOpt)
  479. {
  480. chsMsg.Format(L"IWbemClassObject::Get"
  481. L"(L\"Password\", 0, -, 0, 0)");
  482. GetBstrTFromVariant(vtEmbedProp, bstrResult);
  483. WMITRACEORERRORLOG(hr, __LINE__, __FILE__,
  484. (LPCWSTR)chsMsg, dwThreadId,
  485. rParsedInfo, m_bTrace,
  486. 0, bstrResult);
  487. }
  488. ONFAILTHROWERROR(hr);
  489. if (vtEmbedProp.vt != VT_NULL &&
  490. vtEmbedProp.vt != VT_EMPTY)
  491. {
  492. if(!rParsedInfo.GetCmdSwitchesObject().
  493. SetAliasPassword((_TCHAR*)vtEmbedProp.bstrVal))
  494. {
  495. rParsedInfo.GetCmdSwitchesObject().
  496. SetErrataCode(OUT_OF_MEMORY);
  497. retCode = PARSER_OUTOFMEMORY;
  498. }
  499. VARIANTCLEAR(vtEmbedProp);
  500. }
  501. }
  502. if(retCode != PARSER_OUTOFMEMORY)
  503. {
  504. if (!(uConnFlag & NODE))
  505. {
  506. // retrieve the value of 'Server' property
  507. hr = pIEmbedObj->Get(_bstr_t(L"Server"),
  508. 0, &vtEmbedProp, 0,0);
  509. if (m_bTrace || m_eloErrLogOpt)
  510. {
  511. chsMsg.Format(L"IWbemClassObject::Get"
  512. L"(L\"Server\", 0, -, 0, 0)");
  513. GetBstrTFromVariant(vtEmbedProp, bstrResult);
  514. WMITRACEORERRORLOG(hr, __LINE__, __FILE__,
  515. (LPCWSTR)chsMsg,dwThreadId,
  516. rParsedInfo, m_bTrace,
  517. 0, bstrResult);
  518. }
  519. ONFAILTHROWERROR(hr);
  520. if (vtEmbedProp.vt != VT_NULL &&
  521. vtEmbedProp.vt != VT_EMPTY)
  522. {
  523. if(!rParsedInfo.GetCmdSwitchesObject().
  524. SetAliasNode((_TCHAR*)vtEmbedProp.bstrVal))
  525. {
  526. rParsedInfo.GetCmdSwitchesObject().
  527. SetErrataCode(OUT_OF_MEMORY);
  528. retCode = PARSER_OUTOFMEMORY;
  529. }
  530. VARIANTCLEAR(vtEmbedProp);
  531. }
  532. }
  533. if (retCode != PARSER_OUTOFMEMORY)
  534. {
  535. // retrieve the value of 'Authority' property
  536. hr = pIEmbedObj->Get(_bstr_t(L"Authority"),
  537. 0, &vtEmbedProp, 0,0);
  538. if (m_bTrace || m_eloErrLogOpt)
  539. {
  540. chsMsg.Format(L"IWbemClassObject::Get"
  541. L"(L\"Authority\", 0, -, 0, 0)");
  542. GetBstrTFromVariant(vtEmbedProp, bstrResult);
  543. WMITRACEORERRORLOG(hr, __LINE__, __FILE__,
  544. (LPCWSTR)chsMsg,dwThreadId,
  545. rParsedInfo, m_bTrace,
  546. 0, bstrResult);
  547. }
  548. ONFAILTHROWERROR(hr);
  549. if (vtEmbedProp.vt != VT_NULL &&
  550. vtEmbedProp.vt != VT_EMPTY)
  551. {
  552. if(!rParsedInfo.GetCmdSwitchesObject().
  553. SetAliasAuthorityPrinciple((_TCHAR*)vtEmbedProp.bstrVal))
  554. {
  555. rParsedInfo.GetCmdSwitchesObject().
  556. SetErrataCode(OUT_OF_MEMORY);
  557. retCode = PARSER_OUTOFMEMORY;
  558. }
  559. VARIANTCLEAR(vtEmbedProp);
  560. }
  561. }
  562. }
  563. }
  564. }
  565. }
  566. }
  567. catch(_com_error& e)
  568. {
  569. rParsedInfo.GetCmdSwitchesObject().SetCOMError(e);
  570. retCode = PARSER_OUTOFMEMORY;
  571. VARIANTCLEAR(vtEmbedProp);
  572. }
  573. catch(CHeap_Exception)
  574. {
  575. retCode = PARSER_OUTOFMEMORY;
  576. VARIANTCLEAR(vtEmbedProp);
  577. hr = WBEM_E_OUT_OF_MEMORY;
  578. _com_issue_error(hr);
  579. }
  580. return retCode;
  581. }
  582. /*----------------------------------------------------------------------------
  583. Name :ObtainAliasVerbDetails
  584. Synopsis :Obtains the verbs and their details associated with the
  585. alias object and updates the CCommandSwitches of
  586. CParsedInfo object passed to it.
  587. Type :Member Function
  588. Input parameter(s):
  589. rParsedInfo - The parsed info from command line input.
  590. Output parameter(s):
  591. rParsedInfo - The parsed info from command line input.
  592. Return Type :HRESULT
  593. Global Variables :None
  594. Calling Syntax :ObtainAliasVerbDetails(rParsedInfo)
  595. Notes :None
  596. ----------------------------------------------------------------------------*/
  597. HRESULT CCmdAlias::ObtainAliasVerbDetails(CParsedInfo& rParsedInfo)
  598. {
  599. // variables being used in this function.
  600. IWbemClassObject *pIWbemObj = NULL;
  601. IWbemClassObject *pIEmbedObj = NULL;
  602. IWbemClassObject *pIEmbedObj2 = NULL;
  603. HRESULT hr = S_OK;
  604. _TCHAR szNumber[BUFFER512] = NULL_STRING;
  605. DWORD dwThreadId = GetCurrentThreadId();
  606. VARIANT vtVerbs, vtVerbName, vtParameters,
  607. vtParaId, vtParaType, vtVerbType,
  608. vtVerbDerivation, vtDefaultParamValue;
  609. VariantInit(&vtVerbs);
  610. VariantInit(&vtVerbName);
  611. VariantInit(&vtParameters);
  612. VariantInit(&vtParaId);
  613. VariantInit(&vtParaType);
  614. VariantInit(&vtVerbType);
  615. VariantInit(&vtVerbDerivation);
  616. VariantInit(&vtDefaultParamValue);
  617. try
  618. {
  619. CHString chsMsg;
  620. _bstr_t bstrResult;
  621. // Initialize methDetMap each time.
  622. rParsedInfo.GetCmdSwitchesObject().GetMethDetMap().clear();
  623. _bstr_t bstrPath = _bstr_t("MSFT_CliAlias.FriendlyName='") +
  624. _bstr_t(rParsedInfo.GetCmdSwitchesObject().GetAliasName())+
  625. _bstr_t(L"'");
  626. //Retrieving the object from the namespace in m_pIAliasNS
  627. hr = m_pIAliasNS->GetObject(bstrPath, 0, NULL, &pIWbemObj, NULL);
  628. if (m_bTrace || m_eloErrLogOpt)
  629. {
  630. chsMsg.Format(L"IWbemServices::GetObject(L\"%s\", 0, NULL, -)",
  631. (WCHAR*) bstrPath);
  632. WMITRACEORERRORLOG(hr, __LINE__, __FILE__, (LPCWSTR)chsMsg,
  633. dwThreadId, rParsedInfo, m_bTrace);
  634. }
  635. ONFAILTHROWERROR(hr);
  636. // Obtain verb name and method name to get info of verb name
  637. // or method name only if they are specified.
  638. _TCHAR* pVerbName = rParsedInfo.GetCmdSwitchesObject().GetVerbName();
  639. _TCHAR* pMethodName = rParsedInfo.GetCmdSwitchesObject().
  640. GetMethodName();
  641. BOOL bCompareVerb = FALSE, bCompareMethod = FALSE;
  642. if ( pVerbName != NULL &&
  643. CompareTokens(pVerbName,CLI_TOKEN_CALL) &&
  644. pMethodName != NULL )
  645. bCompareMethod = TRUE;
  646. else if ( pVerbName != NULL &&
  647. !CompareTokens(pVerbName,CLI_TOKEN_CALL))
  648. bCompareVerb = TRUE;
  649. // Get "Verbs" property.
  650. hr = pIWbemObj->Get(_bstr_t(L"Verbs"), 0, &vtVerbs, 0, 0) ;
  651. if (m_bTrace || m_eloErrLogOpt)
  652. {
  653. chsMsg.Format(L"IWbemClassObject::Get(L\"Verbs\", 0, -, 0, 0)");
  654. GetBstrTFromVariant(vtVerbs, bstrResult);
  655. WMITRACEORERRORLOG(hr, __LINE__, __FILE__, (LPCWSTR)chsMsg,
  656. dwThreadId, rParsedInfo, m_bTrace,
  657. 0, bstrResult);
  658. }
  659. ONFAILTHROWERROR(hr);
  660. if ( vtVerbs.vt != VT_EMPTY && vtVerbs.vt != VT_NULL)
  661. {
  662. // Get lower and upper bounds of Verbs array
  663. LONG lUpper = 0, lLower = 0;
  664. hr = SafeArrayGetLBound(vtVerbs.parray, vtVerbs.parray->cDims,
  665. &lLower);
  666. if ( m_eloErrLogOpt )
  667. {
  668. chsMsg.Format(L"SafeArrayGetLBound(-, -, -)");
  669. WMITRACEORERRORLOG(hr, __LINE__, __FILE__, (LPCWSTR)chsMsg,
  670. dwThreadId, rParsedInfo, FALSE);
  671. }
  672. ONFAILTHROWERROR(hr);
  673. hr = SafeArrayGetUBound(vtVerbs.parray, vtVerbs.parray->cDims,
  674. &lUpper);
  675. if ( m_eloErrLogOpt )
  676. {
  677. chsMsg.Format(L"SafeArrayGetUBound(-, -, -)");
  678. WMITRACEORERRORLOG(hr, __LINE__, __FILE__, (LPCWSTR)chsMsg,
  679. dwThreadId, rParsedInfo, FALSE);
  680. }
  681. ONFAILTHROWERROR(hr);
  682. for (LONG lIndex = lLower; lIndex <= lUpper; lIndex++)
  683. {
  684. pIEmbedObj = NULL;
  685. // Get "Name" property.
  686. hr = SafeArrayGetElement(vtVerbs.parray,&lIndex,&pIEmbedObj);
  687. if ( m_eloErrLogOpt )
  688. {
  689. chsMsg.Format(L"SafeArrayGetElement(-, -, -)");
  690. WMITRACEORERRORLOG(hr, __LINE__, __FILE__,(LPCWSTR)chsMsg,
  691. dwThreadId, rParsedInfo, FALSE);
  692. }
  693. ONFAILTHROWERROR(hr);
  694. hr = pIEmbedObj->Get(_bstr_t(L"Name"),0,&vtVerbName,0,0);
  695. if (m_bTrace || m_eloErrLogOpt)
  696. {
  697. chsMsg.Format(L"IWbemClassObject::Get(L\"Name\", 0, -,"
  698. L"0, 0)");
  699. GetBstrTFromVariant(vtVerbName, bstrResult);
  700. WMITRACEORERRORLOG(hr, __LINE__, __FILE__,(LPCWSTR)chsMsg,
  701. dwThreadId, rParsedInfo, m_bTrace,
  702. 0, bstrResult);
  703. }
  704. ONFAILTHROWERROR(hr);
  705. // if user defined verb or method is specified then get info
  706. // of only related to user defined or method name.
  707. BOOL bContinue = FALSE;
  708. if ( bCompareMethod == TRUE &&
  709. !CompareTokens(pMethodName,
  710. (_TCHAR*)_bstr_t(vtVerbName.bstrVal) ) )
  711. bContinue = TRUE;
  712. else if ( bCompareVerb == TRUE &&
  713. !CompareTokens(pVerbName,
  714. (_TCHAR*)_bstr_t(vtVerbName.bstrVal)))
  715. bContinue = TRUE;
  716. if ( bContinue == TRUE )
  717. {
  718. SAFEIRELEASE(pIEmbedObj);
  719. continue;
  720. }
  721. _bstr_t bstrDesc;
  722. hr = GetDescOfObject(pIEmbedObj, bstrDesc, rParsedInfo);
  723. ONFAILTHROWERROR(hr);
  724. // Obtaining the input parameters and thier type.
  725. // Get "Parameters" property.
  726. hr = pIEmbedObj->Get(_bstr_t(L"Parameters"),
  727. 0, &vtParameters, 0, 0);
  728. if (m_bTrace || m_eloErrLogOpt)
  729. {
  730. chsMsg.Format(L"IWbemClassObject::Get(L\"Parameters\","
  731. L"0, -, 0, 0)");
  732. GetBstrTFromVariant(vtParameters, bstrResult);
  733. WMITRACEORERRORLOG(hr, __LINE__, __FILE__,(LPCWSTR)chsMsg,
  734. dwThreadId, rParsedInfo, m_bTrace,
  735. 0, bstrResult);
  736. }
  737. ONFAILTHROWERROR(hr);
  738. if ( vtVerbName.vt != VT_EMPTY && vtVerbName.vt != VT_NULL )
  739. {
  740. if ( bCompareVerb == TRUE || bCompareMethod == TRUE)
  741. {
  742. // Get "VerbType" property.
  743. hr = pIEmbedObj->Get(_bstr_t(L"VerbType"),
  744. 0, &vtVerbType, 0, 0);
  745. if (m_bTrace || m_eloErrLogOpt)
  746. {
  747. chsMsg.Format(L"IWbemClassObject::Get"
  748. L"(L\"VerbType\", 0, -, 0, 0)");
  749. GetBstrTFromVariant(vtVerbType, bstrResult);
  750. WMITRACEORERRORLOG(hr, __LINE__, __FILE__,
  751. (LPCWSTR)chsMsg, dwThreadId,
  752. rParsedInfo, m_bTrace,
  753. 0, bstrResult );
  754. }
  755. ONFAILTHROWERROR(hr);
  756. if ( vtVerbType.vt == VT_I4 )
  757. {
  758. rParsedInfo.GetCmdSwitchesObject().SetVerbType(
  759. VERBTYPE(V_I4(&vtVerbType)));
  760. }
  761. else
  762. {
  763. rParsedInfo.GetCmdSwitchesObject().SetVerbType(
  764. NONALIAS);
  765. }
  766. // Get "Derivation" property.
  767. hr = pIEmbedObj->Get(_bstr_t(L"Derivation"), 0,
  768. &vtVerbDerivation, 0, 0);
  769. if (m_bTrace || m_eloErrLogOpt)
  770. {
  771. chsMsg.Format(L"IWbemClassObject::Get"
  772. L"(L\"Derivation\", 0, -, 0, 0)");
  773. GetBstrTFromVariant(vtVerbDerivation, bstrResult);
  774. WMITRACEORERRORLOG(hr, __LINE__, __FILE__,
  775. (LPCWSTR)chsMsg, dwThreadId,
  776. rParsedInfo, m_bTrace,
  777. 0, bstrResult);
  778. }
  779. ONFAILTHROWERROR(hr);
  780. if ( vtVerbDerivation.vt == VT_BSTR )
  781. rParsedInfo.GetCmdSwitchesObject().
  782. SetVerbDerivation(
  783. _bstr_t(vtVerbDerivation.bstrVal));
  784. }
  785. METHODDETAILS mdMethDet;
  786. mdMethDet.Description = bstrDesc;
  787. if ( vtParameters.vt != VT_EMPTY &&
  788. vtParameters.vt != VT_NULL )
  789. {
  790. // Get lower and upper bounds of Descriptions array
  791. LONG lUpper = 0, lLower = 0;
  792. hr = SafeArrayGetLBound(vtParameters.parray,
  793. vtParameters.parray->cDims, &lLower);
  794. if ( m_eloErrLogOpt )
  795. {
  796. chsMsg.Format(L"SafeArrayGetLBound(-, -, -)");
  797. WMITRACEORERRORLOG(hr, __LINE__, __FILE__,
  798. (LPCWSTR)chsMsg, dwThreadId,
  799. rParsedInfo, FALSE);
  800. }
  801. ONFAILTHROWERROR(hr);
  802. hr = SafeArrayGetUBound(vtParameters.parray,
  803. vtParameters.parray->cDims, &lUpper);
  804. if ( m_eloErrLogOpt )
  805. {
  806. chsMsg.Format(L"SafeArrayGetUBound(-, -, -)");
  807. WMITRACEORERRORLOG(hr, __LINE__, __FILE__,
  808. (LPCWSTR)chsMsg, dwThreadId,
  809. rParsedInfo, FALSE);
  810. }
  811. ONFAILTHROWERROR(hr);
  812. for (LONG lIndex = lLower; lIndex <= lUpper; lIndex++)
  813. {
  814. hr = SafeArrayGetElement(vtParameters.parray,
  815. &lIndex, &pIEmbedObj2);
  816. if ( m_eloErrLogOpt )
  817. {
  818. chsMsg.Format(L"SafeArrayGetElement(-, -, -)");
  819. WMITRACEORERRORLOG(hr, __LINE__, __FILE__,
  820. (LPCWSTR)chsMsg,dwThreadId,
  821. rParsedInfo, FALSE);
  822. }
  823. ONFAILTHROWERROR(hr);
  824. // Get "ParaId" property.
  825. hr = pIEmbedObj2->Get(_bstr_t(L"ParaId"),
  826. 0, &vtParaId, 0, 0);
  827. if (m_bTrace || m_eloErrLogOpt)
  828. {
  829. chsMsg.Format(L"IWbemClassObject::Get"
  830. L"(L\"ParaId\", 0, -, 0, 0)");
  831. GetBstrTFromVariant(vtParaId, bstrResult);
  832. WMITRACEORERRORLOG(hr, __LINE__, __FILE__,
  833. (LPCWSTR)chsMsg,dwThreadId,
  834. rParsedInfo, m_bTrace,
  835. 0, bstrResult);
  836. }
  837. ONFAILTHROWERROR(hr);
  838. // Get "Type" property.
  839. hr = pIEmbedObj2->Get(_bstr_t(L"Type"), 0,
  840. &vtParaType, 0, 0);
  841. if (m_bTrace || m_eloErrLogOpt)
  842. {
  843. chsMsg.Format(L"IWbemClassObject::Get"
  844. L"(L\"Type\", 0, -, 0, 0)");
  845. GetBstrTFromVariant(vtParaType, bstrResult);
  846. WMITRACEORERRORLOG(hr, __LINE__, __FILE__,
  847. (LPCWSTR)chsMsg,dwThreadId,
  848. rParsedInfo, m_bTrace,
  849. 0, bstrResult);
  850. }
  851. ONFAILTHROWERROR(hr);
  852. // Get "Default" property.
  853. hr = pIEmbedObj2->Get(_bstr_t(L"Default"), 0,
  854. &vtDefaultParamValue, 0, 0);
  855. if (m_bTrace || m_eloErrLogOpt)
  856. {
  857. chsMsg.Format(L"IWbemClassObject::Get"
  858. L"(L\"Default\", 0, -, 0, 0)");
  859. GetBstrTFromVariant(vtDefaultParamValue,
  860. bstrResult);
  861. WMITRACEORERRORLOG(hr, __LINE__, __FILE__,
  862. (LPCWSTR)chsMsg,dwThreadId,
  863. rParsedInfo, m_bTrace,
  864. 0, bstrResult);
  865. }
  866. ONFAILTHROWERROR(hr);
  867. if ( vtParaId.vt != VT_EMPTY &&
  868. vtParaId.vt != VT_NULL )
  869. {
  870. PROPERTYDETAILS pdPropDet;
  871. pdPropDet.InOrOut = UNKNOWN;
  872. hr = GetQualifiers(pIEmbedObj2, pdPropDet,
  873. rParsedInfo);
  874. if ( vtParaType.vt == VT_BSTR )
  875. pdPropDet.Type = vtParaType.bstrVal;
  876. else
  877. pdPropDet.Type = _bstr_t("Not Available");
  878. if ( vtDefaultParamValue.vt == VT_BSTR )
  879. pdPropDet.Default = vtDefaultParamValue.
  880. bstrVal;
  881. // Making bstrPropName begin with numbers to
  882. // maintain the order of method arguments in
  883. // map. while displaying remove numbers and
  884. // display the parameters in case of help only
  885. // Also for named paramlist and cmdline
  886. // utility processing.
  887. _bstr_t bstrNumberedPropName;
  888. if ( rParsedInfo.GetGlblSwitchesObject().
  889. GetHelpFlag() ||
  890. rParsedInfo.GetCmdSwitchesObject().
  891. GetVerbType() == CMDLINE )
  892. {
  893. _TCHAR szMsg[BUFFER512];
  894. _ltot(lIndex, szNumber, 10);
  895. _stprintf(szMsg, _T("%-5s"), szNumber);
  896. bstrNumberedPropName = _bstr_t(szMsg) +
  897. _bstr_t(vtParaId.bstrVal);
  898. }
  899. else
  900. bstrNumberedPropName =
  901. _bstr_t(vtParaId.bstrVal);
  902. mdMethDet.Params.insert(
  903. PROPDETMAP::value_type(
  904. bstrNumberedPropName, pdPropDet));
  905. }
  906. VARIANTCLEAR(vtParaId);
  907. VARIANTCLEAR(vtParaType);
  908. VARIANTCLEAR(vtDefaultParamValue);
  909. SAFEIRELEASE(pIEmbedObj2);
  910. }
  911. }
  912. rParsedInfo.GetCmdSwitchesObject().AddToMethDetMap
  913. (vtVerbName.bstrVal, mdMethDet);
  914. }
  915. VARIANTCLEAR(vtVerbName);
  916. VARIANTCLEAR(vtVerbType);
  917. VARIANTCLEAR(vtVerbDerivation);
  918. VARIANTCLEAR(vtParameters);
  919. SAFEIRELEASE(pIEmbedObj);
  920. if ( bCompareVerb == TRUE || bCompareMethod == TRUE)
  921. break;
  922. }
  923. }
  924. VARIANTCLEAR(vtVerbs);
  925. SAFEIRELEASE(pIWbemObj);
  926. }
  927. catch(_com_error& e)
  928. {
  929. SAFEIRELEASE(pIWbemObj);
  930. SAFEIRELEASE(pIEmbedObj);
  931. VARIANTCLEAR(vtVerbs);
  932. VARIANTCLEAR(vtVerbName);
  933. VARIANTCLEAR(vtVerbType);
  934. VARIANTCLEAR(vtVerbDerivation);
  935. VARIANTCLEAR(vtDefaultParamValue);
  936. hr = e.Error();
  937. rParsedInfo.GetCmdSwitchesObject().SetCOMError(e);
  938. }
  939. catch(CHeap_Exception)
  940. {
  941. SAFEIRELEASE(pIWbemObj);
  942. SAFEIRELEASE(pIEmbedObj);
  943. VARIANTCLEAR(vtVerbs);
  944. VARIANTCLEAR(vtVerbName);
  945. VARIANTCLEAR(vtVerbType);
  946. VARIANTCLEAR(vtVerbDerivation);
  947. VARIANTCLEAR(vtDefaultParamValue);
  948. hr = WBEM_E_OUT_OF_MEMORY;
  949. _com_issue_error(hr);
  950. }
  951. return hr;
  952. }
  953. /*----------------------------------------------------------------------------
  954. Name :ObtainAliasFriendlyNames
  955. Synopsis :Obtains all the Friendly Names and descriptions in the
  956. CmdAlias and updates it in the CCommandSwitches of
  957. CParsedInfo object passed to it.
  958. Type :Member Function
  959. Input parameter(s):
  960. rParsedInfo - The parsed info from command line input.
  961. Output parameter(s):
  962. rParsedInfo - The parsed info from command line input.
  963. Return Type :HRESULT
  964. Global Variables :None
  965. Calling Syntax :ObtainAliasFriendlyNames(rParsedInfo)
  966. Notes :None
  967. ----------------------------------------------------------------------------*/
  968. HRESULT CCmdAlias::ObtainAliasFriendlyNames(CParsedInfo& rParsedInfo)
  969. {
  970. // variables being used in this function.
  971. HRESULT hr = S_OK;
  972. IEnumWbemClassObject *pIEnumObj = NULL;
  973. IWbemClassObject *pIWbemObj = NULL;
  974. DWORD dwThreadId = GetCurrentThreadId();
  975. VARIANT vtName;
  976. VariantInit(&vtName);
  977. try
  978. {
  979. CHString chsMsg;
  980. _bstr_t bstrResult;
  981. // Get alias object
  982. hr = m_pIAliasNS->ExecQuery(_bstr_t(L"WQL"),
  983. _bstr_t(L"SELECT * FROM MSFT_CliAlias"),
  984. WBEM_FLAG_FORWARD_ONLY|
  985. WBEM_FLAG_RETURN_IMMEDIATELY,
  986. NULL, &pIEnumObj);
  987. if (m_bTrace || m_eloErrLogOpt)
  988. {
  989. chsMsg.Format(L"IWbemServices::ExecQuery(L\"WQL\","
  990. L"L\"SELECT * FROM MSFT_CliAlias\","
  991. L"WBEM_FLAG_FORWARD_ONLY|WBEM_FLAG_RETURN_IMMEDIATELY,"
  992. L"NULL, -)");
  993. WMITRACEORERRORLOG(hr, __LINE__, __FILE__, (LPCWSTR)chsMsg,
  994. dwThreadId, rParsedInfo, m_bTrace);
  995. }
  996. ONFAILTHROWERROR(hr);
  997. // Set the security
  998. hr = SetSecurity(pIEnumObj, NULL, NULL, NULL, NULL,
  999. rParsedInfo.GetGlblSwitchesObject().GetAuthenticationLevel(),
  1000. rParsedInfo.GetGlblSwitchesObject().GetImpersonationLevel());
  1001. if (m_bTrace || m_eloErrLogOpt)
  1002. {
  1003. chsMsg.Format(
  1004. L"CoSetProxyBlanket(-, RPC_C_AUTHN_WINNT, RPC_C_AUTHZ_NONE,"
  1005. L"NULL, %d, %d, -, EOAC_NONE)",
  1006. rParsedInfo.GetGlblSwitchesObject().GetAuthenticationLevel(),
  1007. rParsedInfo.GetGlblSwitchesObject().GetImpersonationLevel());
  1008. WMITRACEORERRORLOG(hr, __LINE__, __FILE__, (LPCWSTR)chsMsg,
  1009. dwThreadId, rParsedInfo, m_bTrace);
  1010. }
  1011. ONFAILTHROWERROR(hr);
  1012. ULONG ulReturned = 0;
  1013. // Obtain the object starting at the current position in the
  1014. // enumeration and loop through the instance list.
  1015. while(((hr=pIEnumObj->Next(WBEM_INFINITE,1,&pIWbemObj,&ulReturned))==
  1016. S_OK) && (ulReturned == 1))
  1017. {
  1018. VariantInit(&vtName);
  1019. // Gets "FriendlyName" array property of alias object
  1020. hr = pIWbemObj->Get(_bstr_t(L"FriendlyName"), 0, &vtName, 0, 0);
  1021. if (m_bTrace || m_eloErrLogOpt)
  1022. {
  1023. chsMsg.Format(L"IWbemClassObject::Get(L\"FriendlyName\", 0,"
  1024. L"-, 0, 0)");
  1025. GetBstrTFromVariant(vtName, bstrResult);
  1026. WMITRACEORERRORLOG(hr, __LINE__, __FILE__, (LPCWSTR)chsMsg,
  1027. dwThreadId, rParsedInfo, m_bTrace,
  1028. 0, bstrResult);
  1029. }
  1030. ONFAILTHROWERROR(hr);
  1031. if (vtName.vt != VT_NULL && vtName.vt != VT_EMPTY)
  1032. {
  1033. _bstr_t bstrFriendlyName = vtName.bstrVal;
  1034. _bstr_t bstrDesc;
  1035. hr = GetDescOfObject(pIWbemObj, bstrDesc, rParsedInfo, TRUE);
  1036. ONFAILTHROWERROR(hr);
  1037. //Add the "FriendlyName" to FriendlyName Map
  1038. rParsedInfo.GetCmdSwitchesObject().
  1039. AddToAlsFrnNmsOrTrnsTblMap(CharUpper(bstrFriendlyName)
  1040. ,bstrDesc);
  1041. }
  1042. VARIANTCLEAR(vtName);
  1043. SAFEIRELEASE(pIWbemObj);
  1044. }
  1045. SAFEIRELEASE(pIEnumObj);
  1046. }
  1047. catch(_com_error& e)
  1048. {
  1049. SAFEIRELEASE(pIEnumObj);
  1050. SAFEIRELEASE(pIWbemObj);
  1051. VARIANTCLEAR(vtName);
  1052. hr = e.Error();
  1053. rParsedInfo.GetCmdSwitchesObject().SetCOMError(e);
  1054. }
  1055. catch(CHeap_Exception)
  1056. {
  1057. SAFEIRELEASE(pIEnumObj);
  1058. SAFEIRELEASE(pIWbemObj);
  1059. VARIANTCLEAR(vtName);
  1060. hr = WBEM_E_OUT_OF_MEMORY;
  1061. _com_issue_error(hr);
  1062. }
  1063. return hr;
  1064. }
  1065. /*----------------------------------------------------------------------------
  1066. Name :ObtainAliasFormat
  1067. Synopsis :Obtains the Derivation of the properties for the Format
  1068. associated with the alias object and updates the
  1069. CCommandSwitches of CParsedInfo object passed to it.
  1070. Type :Member Function
  1071. Input parameter(s):
  1072. rParsedInfo - The parsed info from command line input.
  1073. Output parameter(s):
  1074. rParsedInfo - The parsed info from command line input.
  1075. Return Type :BOOL : TRUE - if valid format is not present
  1076. FALSE - if invalid format
  1077. Global Variables :None
  1078. Calling Syntax :ObtainAliasFormat(rParsedInfo)
  1079. Notes :If bCheckForListFrmsAvail == TRUE then functions checks
  1080. only for availibilty of list formats with the alias.
  1081. ----------------------------------------------------------------------------*/
  1082. BOOL CCmdAlias::ObtainAliasFormat(CParsedInfo& rParsedInfo,
  1083. BOOL bCheckForListFrmsAvail)
  1084. {
  1085. // variables being used in this function.
  1086. HRESULT hr = S_OK;
  1087. IWbemClassObject *pIWbemObj = NULL;
  1088. IWbemClassObject *pIEmbedObj = NULL;
  1089. IWbemClassObject *pIEmbedObj2 = NULL;
  1090. BOOL bExist = FALSE;
  1091. DWORD dwThreadId = GetCurrentThreadId();
  1092. VARIANT vtFormats, vtFormatName,
  1093. vtProperties, vtPropertyName, vtPropertyDerivation ;
  1094. BOOL bHelp = rParsedInfo.
  1095. GetGlblSwitchesObject().
  1096. GetHelpFlag();
  1097. // Initializing all Variants variables being used in this function.
  1098. VariantInit(&vtFormats);
  1099. VariantInit(&vtFormatName);
  1100. VariantInit(&vtProperties);
  1101. VariantInit(&vtPropertyName);
  1102. VariantInit(&vtPropertyDerivation);
  1103. try
  1104. {
  1105. CHString chsMsg;
  1106. _bstr_t bstrResult;
  1107. _bstr_t bstrPath = _bstr_t("MSFT_CliAlias.FriendlyName='") +
  1108. _bstr_t(rParsedInfo.GetCmdSwitchesObject().GetAliasName())+
  1109. _bstr_t(L"'");
  1110. // Get alias object
  1111. hr = m_pIAliasNS->GetObject(bstrPath, 0, NULL, &pIWbemObj, NULL);
  1112. if (m_bTrace || m_eloErrLogOpt)
  1113. {
  1114. chsMsg.Format(L"IWbemServices::GetObject(L\"%s\", 0, NULL, -)",
  1115. (WCHAR*) bstrPath);
  1116. WMITRACEORERRORLOG(hr, __LINE__, __FILE__, (LPCWSTR)chsMsg,
  1117. dwThreadId, rParsedInfo, m_bTrace);
  1118. }
  1119. ONFAILTHROWERROR(hr);
  1120. // Get Formats array property of alias object
  1121. hr = pIWbemObj->Get(_bstr_t(L"Formats"), 0, &vtFormats, 0, 0);
  1122. if (m_bTrace || m_eloErrLogOpt)
  1123. {
  1124. chsMsg.Format(L"IWbemClassObject::Get(L\"Formats\", 0, -,0, 0)");
  1125. GetBstrTFromVariant(vtFormats, bstrResult);
  1126. WMITRACEORERRORLOG(hr, __LINE__, __FILE__, (LPCWSTR)chsMsg,
  1127. dwThreadId, rParsedInfo, m_bTrace,
  1128. 0, bstrResult);
  1129. }
  1130. ONFAILTHROWERROR(hr);
  1131. if ( vtFormats.vt != VT_NULL && vtFormats.vt != VT_EMPTY
  1132. && bCheckForListFrmsAvail == FALSE)
  1133. {
  1134. // Get lower and upper bounds of Formats array
  1135. LONG lUpper = 0, lLower = 0;
  1136. hr = SafeArrayGetLBound(vtFormats.parray, vtFormats.parray->cDims,
  1137. &lLower);
  1138. if ( m_eloErrLogOpt )
  1139. {
  1140. chsMsg.Format(L"SafeArrayGetLBound(-, -, -)");
  1141. WMITRACEORERRORLOG(hr, __LINE__, __FILE__, (LPCWSTR)chsMsg,
  1142. dwThreadId, rParsedInfo, FALSE);
  1143. }
  1144. ONFAILTHROWERROR(hr);
  1145. hr = SafeArrayGetUBound(vtFormats.parray, vtFormats.parray->cDims,
  1146. &lUpper);
  1147. if ( m_eloErrLogOpt )
  1148. {
  1149. chsMsg.Format(L"SafeArrayGetUBound(-, -, -)");
  1150. WMITRACEORERRORLOG(hr, __LINE__, __FILE__, (LPCWSTR)chsMsg,
  1151. dwThreadId, rParsedInfo, FALSE);
  1152. }
  1153. ONFAILTHROWERROR(hr);
  1154. // Iterate through the Formats array property
  1155. for (LONG lIndex = lLower; lIndex <= lUpper; lIndex++)
  1156. {
  1157. // Get this property.
  1158. hr =SafeArrayGetElement(vtFormats.parray,&lIndex,&pIEmbedObj);
  1159. if ( m_eloErrLogOpt )
  1160. {
  1161. chsMsg.Format(L"SafeArrayGetElement(-, -, -)");
  1162. WMITRACEORERRORLOG(hr, __LINE__, __FILE__,(LPCWSTR)chsMsg,
  1163. dwThreadId, rParsedInfo, FALSE);
  1164. }
  1165. ONFAILTHROWERROR(hr);
  1166. hr = pIEmbedObj->Get(_bstr_t(L"Name"),0,&vtFormatName,0,0);
  1167. if (m_bTrace || m_eloErrLogOpt)
  1168. {
  1169. chsMsg.Format(L"IWbemClassObject::Get(L\"Name\", 0,"
  1170. L"-, 0, 0)");
  1171. GetBstrTFromVariant(vtFormatName, bstrResult);
  1172. WMITRACEORERRORLOG(hr, __LINE__, __FILE__,(LPCWSTR)chsMsg,
  1173. dwThreadId, rParsedInfo, m_bTrace,
  1174. 0, bstrResult);
  1175. }
  1176. ONFAILTHROWERROR(hr);
  1177. //Comparing the specified Format in the alias against the
  1178. //formats available for the specified alias.
  1179. if(CompareTokens(_bstr_t(rParsedInfo.GetCmdSwitchesObject().
  1180. GetListFormat()), _bstr_t(vtFormatName.bstrVal)))
  1181. {
  1182. bExist = TRUE;
  1183. VARIANT vtFormat;
  1184. VariantInit(&vtFormat);
  1185. //Getting the "Format" property.
  1186. hr = pIEmbedObj->Get(_bstr_t(L"Format"),0,
  1187. &vtFormat, 0, 0);
  1188. if (m_bTrace || m_eloErrLogOpt)
  1189. {
  1190. chsMsg.Format( L"IWbemClassObject::Get(L\"Format\","
  1191. L"0, -, 0, 0)");
  1192. GetBstrTFromVariant(vtFormat, bstrResult);
  1193. WMITRACEORERRORLOG(hr, __LINE__, __FILE__,
  1194. (LPCWSTR)chsMsg, dwThreadId,
  1195. rParsedInfo, m_bTrace,
  1196. 0, bstrResult);
  1197. }
  1198. ONFAILTHROWERROR(hr);
  1199. if ( vtFormat.vt != VT_EMPTY && vtFormat.vt != VT_NULL )
  1200. {
  1201. if (rParsedInfo.GetCmdSwitchesObject().
  1202. GetXSLTDetailsVector().empty())
  1203. {
  1204. _bstr_t bstrFileName ;
  1205. // If _T("") is the value, it should be treated as
  1206. // equivalent to <empty>
  1207. if (CompareTokens(vtFormat.bstrVal, _T("")))
  1208. {
  1209. FrameFileAndAddToXSLTDetVector (
  1210. XSL_FORMAT_TABLE,
  1211. CLI_TOKEN_TABLE,
  1212. rParsedInfo
  1213. );
  1214. }
  1215. else
  1216. {
  1217. g_wmiCmd.GetFileFromKey(vtFormat.bstrVal, bstrFileName);
  1218. XSLTDET xdXSLTDet;
  1219. xdXSLTDet.FileName = bstrFileName;
  1220. FrameFileAndAddToXSLTDetVector(xdXSLTDet,
  1221. rParsedInfo);
  1222. }
  1223. }
  1224. }
  1225. VariantClear(&vtFormat);
  1226. //Getting the "Properties" property.
  1227. hr=pIEmbedObj->Get(_bstr_t(L"Properties"),
  1228. 0, &vtProperties, 0, 0);
  1229. if (m_bTrace || m_eloErrLogOpt)
  1230. {
  1231. chsMsg.Format(L"IWbemClassObject::Get(L\"Properties\","
  1232. L"0, -, 0, 0)");
  1233. GetBstrTFromVariant(vtProperties, bstrResult);
  1234. WMITRACEORERRORLOG(hr, __LINE__, __FILE__,
  1235. (LPCWSTR)chsMsg, dwThreadId,
  1236. rParsedInfo, m_bTrace,
  1237. 0, bstrResult);
  1238. }
  1239. ONFAILTHROWERROR(hr);
  1240. if ( vtProperties.vt != VT_NULL )
  1241. {
  1242. LONG lILower = 0, lIUpper = 0;
  1243. hr = SafeArrayGetLBound(vtProperties.parray,
  1244. vtProperties.parray->cDims, &lILower);
  1245. if ( m_eloErrLogOpt )
  1246. {
  1247. chsMsg.Format(L"SafeArrayGetLBound(-, -, -)");
  1248. WMITRACEORERRORLOG(hr, __LINE__, __FILE__,
  1249. (LPCWSTR)chsMsg, dwThreadId,
  1250. rParsedInfo, FALSE);
  1251. }
  1252. ONFAILTHROWERROR(hr);
  1253. hr = SafeArrayGetUBound(vtProperties.parray,
  1254. vtProperties.parray->cDims, &lIUpper);
  1255. if ( m_eloErrLogOpt )
  1256. {
  1257. chsMsg.Format(L"SafeArrayGetUBound(-, -, -)");
  1258. WMITRACEORERRORLOG(hr, __LINE__, __FILE__,
  1259. (LPCWSTR)chsMsg, dwThreadId,
  1260. rParsedInfo, FALSE);
  1261. }
  1262. ONFAILTHROWERROR(hr);
  1263. // Iterate through the Properties array property
  1264. for(LONG lIIndex = lILower;
  1265. lIIndex <= lIUpper;
  1266. lIIndex++)
  1267. {
  1268. // Get this property.
  1269. hr = SafeArrayGetElement(vtProperties.parray,
  1270. &lIIndex, &pIEmbedObj2);
  1271. if ( m_eloErrLogOpt )
  1272. {
  1273. chsMsg.Format(L"SafeArrayGetElement(-, -, -)");
  1274. WMITRACEORERRORLOG(hr, __LINE__, __FILE__,
  1275. (LPCWSTR)chsMsg, dwThreadId,
  1276. rParsedInfo, FALSE);
  1277. }
  1278. ONFAILTHROWERROR(hr);
  1279. //Getting the "Name" property
  1280. hr = pIEmbedObj2->Get(_bstr_t(L"Name"), 0,
  1281. &vtPropertyName,0,0);
  1282. if (m_bTrace || m_eloErrLogOpt)
  1283. {
  1284. chsMsg.Format(L"IWbemClassObject::Get"
  1285. L"(L\"Name\", 0, -, 0, 0)");
  1286. GetBstrTFromVariant(vtPropertyName,
  1287. bstrResult);
  1288. WMITRACEORERRORLOG(hr, __LINE__, __FILE__,
  1289. (LPCWSTR)chsMsg, dwThreadId,
  1290. rParsedInfo, m_bTrace,
  1291. 0, bstrResult);
  1292. }
  1293. ONFAILTHROWERROR(hr);
  1294. //Getting the "Derivation" property
  1295. hr = pIEmbedObj2->Get(_bstr_t(L"Derivation"), 0,
  1296. &vtPropertyDerivation,0,0);
  1297. if (m_bTrace || m_eloErrLogOpt)
  1298. {
  1299. chsMsg.Format(L"IWbemClassObject::Get"
  1300. L"(L\"Derivation\", 0, -, 0, 0)");
  1301. GetBstrTFromVariant(vtPropertyDerivation,
  1302. bstrResult);
  1303. WMITRACEORERRORLOG(hr, __LINE__, __FILE__,
  1304. (LPCWSTR)chsMsg, dwThreadId,
  1305. rParsedInfo, m_bTrace,
  1306. 0, bstrResult);
  1307. }
  1308. ONFAILTHROWERROR(hr);
  1309. _bstr_t bstrPropName;
  1310. if ( bHelp )
  1311. {
  1312. if ( vtPropertyName.vt == VT_BSTR )
  1313. bstrPropName = vtPropertyName.bstrVal;
  1314. }
  1315. else
  1316. {
  1317. if ( vtPropertyDerivation.vt == VT_BSTR )
  1318. bstrPropName = vtPropertyDerivation.bstrVal;
  1319. else if ( vtPropertyName.vt == VT_BSTR )
  1320. bstrPropName = vtPropertyName.bstrVal;
  1321. }
  1322. //Add propertyderivation to property list in
  1323. // rParsedInfo
  1324. if((!bstrPropName == FALSE) &&
  1325. !rParsedInfo.GetCmdSwitchesObject().
  1326. AddToPropertyList(
  1327. (_TCHAR*)bstrPropName))
  1328. {
  1329. rParsedInfo.GetCmdSwitchesObject().
  1330. SetErrataCode(OUT_OF_MEMORY);
  1331. bExist = FALSE;
  1332. VARIANTCLEAR(vtPropertyDerivation);
  1333. break;
  1334. }
  1335. // Add propertyname to property list in
  1336. // rParsedInfo only to avail information of Name
  1337. // and Derivation of list properties for XML
  1338. // logging.
  1339. PROPERTYDETAILS pdPropDet;
  1340. if ( vtPropertyDerivation.vt == VT_BSTR )
  1341. pdPropDet.Derivation =
  1342. vtPropertyDerivation.bstrVal;
  1343. else
  1344. pdPropDet.Derivation = _bstr_t(TOKEN_NA);
  1345. rParsedInfo.GetCmdSwitchesObject().
  1346. AddToPropDetMap(
  1347. vtPropertyName.bstrVal, pdPropDet);
  1348. VARIANTCLEAR(vtPropertyName);
  1349. VARIANTCLEAR(vtPropertyDerivation);
  1350. // Release pIEmbedObj2
  1351. SAFEIRELEASE(pIEmbedObj2);
  1352. }
  1353. }
  1354. // Release memory held by vtProperties
  1355. VARIANTCLEAR(vtProperties);
  1356. // Free memory held by vtFormatName
  1357. VARIANTCLEAR(vtFormatName);
  1358. // Release pIEmbedObj
  1359. SAFEIRELEASE(pIEmbedObj);
  1360. break;
  1361. }
  1362. // Free memory held by vtFormatName
  1363. VARIANTCLEAR(vtFormatName);
  1364. // Release pIEmbedObj
  1365. SAFEIRELEASE(pIEmbedObj);
  1366. }
  1367. // Release memory held by vtFormats
  1368. VARIANTCLEAR(vtFormats);
  1369. }
  1370. else if ( vtFormats.vt != VT_NULL && vtFormats.vt != VT_EMPTY )
  1371. {
  1372. bExist = TRUE;
  1373. }
  1374. // Release pIWbem object
  1375. SAFEIRELEASE(pIWbemObj);
  1376. }
  1377. catch(_com_error& e)
  1378. {
  1379. SAFEIRELEASE(pIWbemObj);
  1380. SAFEIRELEASE(pIEmbedObj);
  1381. SAFEIRELEASE(pIEmbedObj2);
  1382. VARIANTCLEAR(vtFormats);
  1383. VARIANTCLEAR(vtFormatName);
  1384. VARIANTCLEAR(vtProperties);
  1385. VARIANTCLEAR(vtPropertyName);
  1386. VARIANTCLEAR(vtPropertyDerivation);
  1387. rParsedInfo.GetCmdSwitchesObject().SetCOMError(e);
  1388. bExist = FALSE;
  1389. }
  1390. catch(CHeap_Exception)
  1391. {
  1392. SAFEIRELEASE(pIWbemObj);
  1393. SAFEIRELEASE(pIEmbedObj);
  1394. SAFEIRELEASE(pIEmbedObj2);
  1395. VARIANTCLEAR(vtFormats);
  1396. VARIANTCLEAR(vtFormatName);
  1397. VARIANTCLEAR(vtProperties);
  1398. VARIANTCLEAR(vtPropertyName);
  1399. VARIANTCLEAR(vtPropertyDerivation);
  1400. bExist = FALSE;
  1401. hr = WBEM_E_OUT_OF_MEMORY;
  1402. _com_issue_error(hr);
  1403. }
  1404. return bExist;
  1405. }
  1406. /*----------------------------------------------------------------------------
  1407. Name :ObtainAliasPropDetails
  1408. Synopsis :Obtains the details of the properties for the Format
  1409. associated with the alias object and updates the
  1410. CCommandSwitches of CParsedInfo object passed to it.
  1411. Type :Member Function
  1412. Input parameter(s):
  1413. rParsedInfo - The parsed info from command line input.
  1414. Output parameter(s):
  1415. rParsedInfo - The parsed info from command line input.
  1416. Return Type :HRESULT
  1417. Global Variables :None
  1418. Calling Syntax :ObtainAliasPropDetails(rParsedInfo)
  1419. Notes :pbCheckWritePropsAvailInAndOut == TRUE then function
  1420. checks for availibility of properties and returns in
  1421. the same pbCheckWritePropsAvailInAndOut parameter.
  1422. pbCheckFULLPropsAvailInAndOut == TRUE then function
  1423. checks for availibility of alias properties i.e in FULL
  1424. list format.
  1425. Imp : Any one of the input pointers can only be
  1426. specified.
  1427. ----------------------------------------------------------------------------*/
  1428. HRESULT CCmdAlias::ObtainAliasPropDetails(CParsedInfo& rParsedInfo,
  1429. BOOL *pbCheckWritePropsAvailInAndOut,
  1430. BOOL *pbCheckFULLPropsAvailInAndOut)
  1431. {
  1432. // variables being used in this function.
  1433. HRESULT hr = S_OK;
  1434. IWbemClassObject *pIWbemObj = NULL;
  1435. IWbemClassObject *pIEmbedObj = NULL;
  1436. IWbemClassObject *pIEmbedObj2 = NULL;
  1437. BOOL bPropList = FALSE;
  1438. _TCHAR *pszVerbName = NULL;
  1439. DWORD dwThreadId = GetCurrentThreadId();
  1440. VARIANT vtFormats, vtFormatName,
  1441. vtProperties, vtPropertyName, vtPropertyDerivation;
  1442. // Initializing all Variants variables being used in this function.
  1443. VariantInit(&vtFormats);
  1444. VariantInit(&vtFormatName);
  1445. VariantInit(&vtProperties);
  1446. VariantInit(&vtPropertyName);
  1447. VariantInit(&vtPropertyDerivation);
  1448. CHARVECTOR cvPropList;
  1449. if ( pbCheckWritePropsAvailInAndOut != NULL )
  1450. *pbCheckWritePropsAvailInAndOut = FALSE;
  1451. if ( pbCheckFULLPropsAvailInAndOut != NULL )
  1452. *pbCheckFULLPropsAvailInAndOut = FALSE;
  1453. try
  1454. {
  1455. CHString chsMsg;
  1456. _bstr_t bstrResult;
  1457. pszVerbName = rParsedInfo.GetCmdSwitchesObject().GetVerbName();
  1458. cvPropList = rParsedInfo.GetCmdSwitchesObject().GetPropertyList();
  1459. if ( cvPropList.size() != 0 )
  1460. bPropList = TRUE;
  1461. _bstr_t bstrPath = _bstr_t("MSFT_CliAlias.FriendlyName='") +
  1462. _bstr_t(rParsedInfo.GetCmdSwitchesObject().GetAliasName())+
  1463. _bstr_t(L"'");
  1464. // Get alias object
  1465. hr = m_pIAliasNS->GetObject(bstrPath, 0, NULL, &pIWbemObj, NULL);
  1466. if (m_bTrace || m_eloErrLogOpt)
  1467. {
  1468. chsMsg.Format( L"IWbemServices::GetObject(L\"%s\", 0, NULL, -)",
  1469. (WCHAR*) bstrPath);
  1470. WMITRACEORERRORLOG(hr, __LINE__, __FILE__, (LPCWSTR)chsMsg,
  1471. dwThreadId, rParsedInfo, m_bTrace);
  1472. }
  1473. ONFAILTHROWERROR(hr);
  1474. // Get Formats array property of alias object
  1475. hr = pIWbemObj->Get(_bstr_t(L"Formats"), 0, &vtFormats, 0, 0);
  1476. if (m_bTrace || m_eloErrLogOpt)
  1477. {
  1478. chsMsg.Format(L"IWbemClassObject::Get(L\"Formats\", 0,"
  1479. L"-, 0, 0)");
  1480. GetBstrTFromVariant(vtFormats, bstrResult);
  1481. WMITRACEORERRORLOG(hr, __LINE__, __FILE__, (LPCWSTR)chsMsg,
  1482. dwThreadId, rParsedInfo, m_bTrace,
  1483. 0, bstrResult);
  1484. }
  1485. ONFAILTHROWERROR(hr);
  1486. BOOL bSetVerb = pszVerbName != NULL &&
  1487. CompareTokens(pszVerbName,CLI_TOKEN_SET);
  1488. if ( vtFormats.vt != VT_NULL && vtFormats.vt != VT_EMPTY )
  1489. {
  1490. // Get lower and upper bounds of Formats array
  1491. LONG lUpper = 0, lLower = 0;
  1492. hr = SafeArrayGetLBound(vtFormats.parray, vtFormats.parray->cDims,
  1493. &lLower);
  1494. if ( m_eloErrLogOpt )
  1495. {
  1496. chsMsg.Format(L"SafeArrayGetLBound(-, -, -)");
  1497. WMITRACEORERRORLOG(hr, __LINE__, __FILE__, (LPCWSTR)chsMsg,
  1498. dwThreadId, rParsedInfo, FALSE);
  1499. }
  1500. ONFAILTHROWERROR(hr);
  1501. hr = SafeArrayGetUBound(vtFormats.parray,vtFormats.parray->cDims,
  1502. &lUpper);
  1503. if ( m_eloErrLogOpt )
  1504. {
  1505. chsMsg.Format(L"SafeArrayGetUBound(-, -, -)");
  1506. WMITRACEORERRORLOG(hr, __LINE__, __FILE__, (LPCWSTR)chsMsg,
  1507. dwThreadId, rParsedInfo, FALSE);
  1508. }
  1509. ONFAILTHROWERROR(hr);
  1510. // Iterate through the Formats array property
  1511. for (LONG lIndex = lLower; lIndex <= lUpper; lIndex++)
  1512. {
  1513. // Get this property.
  1514. hr=SafeArrayGetElement(vtFormats.parray,&lIndex,&pIEmbedObj);
  1515. if ( m_eloErrLogOpt )
  1516. {
  1517. chsMsg.Format(L"SafeArrayGetElement(-, -, -)");
  1518. WMITRACEORERRORLOG(hr, __LINE__, __FILE__,(LPCWSTR)chsMsg,
  1519. dwThreadId, rParsedInfo, FALSE);
  1520. }
  1521. ONFAILTHROWERROR(hr);
  1522. hr = pIEmbedObj->Get(_bstr_t(L"Name"),0,&vtFormatName,0,0);
  1523. if (m_bTrace || m_eloErrLogOpt)
  1524. {
  1525. chsMsg.Format(L"IWbemClassObject::Get(L\"Name\", 0,"
  1526. L"-, 0, 0)");
  1527. GetBstrTFromVariant(vtFormatName, bstrResult);
  1528. WMITRACEORERRORLOG(hr, __LINE__, __FILE__,(LPCWSTR)chsMsg,
  1529. dwThreadId, rParsedInfo, m_bTrace,
  1530. 0, bstrResult);
  1531. }
  1532. ONFAILTHROWERROR(hr);
  1533. BOOL bGetProps = FALSE;
  1534. if ( pbCheckWritePropsAvailInAndOut != NULL)
  1535. bGetProps = CompareTokens(_bstr_t(vtFormatName.bstrVal),
  1536. _T("WRITEABLE"));
  1537. else if ( pbCheckFULLPropsAvailInAndOut != NULL)
  1538. bGetProps = CompareTokens(_bstr_t(vtFormatName.bstrVal),
  1539. _T("FULL"));
  1540. else
  1541. {
  1542. bGetProps = (bSetVerb) ?
  1543. ((rParsedInfo.GetHelpInfoObject().GetHelp(SETVerb)) ?
  1544. CompareTokens(_bstr_t(vtFormatName.bstrVal),
  1545. _T("WRITEABLE")):
  1546. CompareTokens(_bstr_t(vtFormatName.bstrVal),
  1547. _T("FULL")) ):
  1548. CompareTokens(_bstr_t(vtFormatName.bstrVal),_T("FULL"));
  1549. }
  1550. //Comparing the specified Format in the alias against
  1551. //the formats available for the specified alias.
  1552. if( bGetProps )
  1553. {
  1554. //Getting the "Properties" property.
  1555. hr=pIEmbedObj->Get(_bstr_t(L"Properties"),0,
  1556. &vtProperties, 0, 0);
  1557. if (m_bTrace || m_eloErrLogOpt)
  1558. {
  1559. chsMsg.Format(L"IWbemClassObject::Get"
  1560. L"(L\"Properties\", 0, -, 0, 0)");
  1561. GetBstrTFromVariant(vtProperties, bstrResult);
  1562. WMITRACEORERRORLOG(hr, __LINE__, __FILE__,
  1563. (LPCWSTR)chsMsg, dwThreadId,
  1564. rParsedInfo, m_bTrace,
  1565. 0, bstrResult);
  1566. }
  1567. ONFAILTHROWERROR(hr);
  1568. if ( vtProperties.vt != VT_NULL )
  1569. {
  1570. LONG lILower = 0, lIUpper = 0;
  1571. hr = SafeArrayGetLBound(vtProperties.parray,
  1572. vtProperties.parray->cDims, &lILower);
  1573. if ( m_eloErrLogOpt )
  1574. {
  1575. chsMsg.Format(L"SafeArrayGetLBound(-, -, -)");
  1576. WMITRACEORERRORLOG(hr, __LINE__, __FILE__,
  1577. (LPCWSTR)chsMsg, dwThreadId,
  1578. rParsedInfo, FALSE);
  1579. }
  1580. ONFAILTHROWERROR(hr);
  1581. hr = SafeArrayGetUBound(vtProperties.parray,
  1582. vtProperties.parray->cDims, &lIUpper);
  1583. if ( m_eloErrLogOpt )
  1584. {
  1585. chsMsg.Format(L"SafeArrayGetUBound(-, -, -)");
  1586. WMITRACEORERRORLOG(hr, __LINE__, __FILE__,
  1587. (LPCWSTR)chsMsg, dwThreadId,
  1588. rParsedInfo, FALSE);
  1589. }
  1590. ONFAILTHROWERROR(hr);
  1591. // Iterate through the Properties array property
  1592. for(LONG lIIndex=lILower; lIIndex<=lIUpper; lIIndex++)
  1593. {
  1594. // Get this property.
  1595. hr = SafeArrayGetElement(vtProperties.parray,
  1596. &lIIndex, &pIEmbedObj2);
  1597. if ( m_eloErrLogOpt )
  1598. {
  1599. chsMsg.Format(L"SafeArrayGetElement(-, -, -)");
  1600. WMITRACEORERRORLOG(hr, __LINE__, __FILE__,
  1601. (LPCWSTR)chsMsg,dwThreadId,
  1602. rParsedInfo, FALSE);
  1603. }
  1604. ONFAILTHROWERROR(hr);
  1605. //Getting the "Name" property
  1606. hr = pIEmbedObj2->Get(_bstr_t(L"Name"), 0,
  1607. &vtPropertyName,0,0);
  1608. if (m_bTrace || m_eloErrLogOpt)
  1609. {
  1610. chsMsg.Format(L"IWbemClassObject::Get"
  1611. L"(L\"Name\", 0, -, 0, 0)");
  1612. GetBstrTFromVariant(vtPropertyName,
  1613. bstrResult);
  1614. WMITRACEORERRORLOG(hr, __LINE__, __FILE__,
  1615. (LPCWSTR)chsMsg,dwThreadId,
  1616. rParsedInfo, m_bTrace,
  1617. 0, bstrResult);
  1618. }
  1619. ONFAILTHROWERROR(hr);
  1620. //Getting the "Derivation" property
  1621. hr = pIEmbedObj2->Get(_bstr_t(L"Derivation"), 0,
  1622. &vtPropertyDerivation,0,0);
  1623. if (m_bTrace || m_eloErrLogOpt)
  1624. {
  1625. chsMsg.Format(L"IWbemClassObject::Get"
  1626. L"(L\"Derivation\", 0, -, 0, 0)");
  1627. GetBstrTFromVariant(vtPropertyDerivation,
  1628. bstrResult);
  1629. WMITRACEORERRORLOG(hr, __LINE__, __FILE__,
  1630. (LPCWSTR)chsMsg,dwThreadId,
  1631. rParsedInfo, m_bTrace,
  1632. 0, bstrResult);
  1633. }
  1634. ONFAILTHROWERROR(hr);
  1635. if (vtPropertyName.vt == VT_BSTR)
  1636. {
  1637. CHARVECTOR::iterator tempIterator;
  1638. if ( bPropList == TRUE &&
  1639. !Find(cvPropList,
  1640. _bstr_t(vtPropertyName.bstrVal),
  1641. tempIterator) )
  1642. {
  1643. SAFEIRELEASE(pIEmbedObj2)
  1644. continue;
  1645. }
  1646. if ( pbCheckWritePropsAvailInAndOut != NULL)
  1647. {
  1648. *pbCheckWritePropsAvailInAndOut = TRUE;
  1649. SAFEIRELEASE(pIEmbedObj2);
  1650. break;
  1651. }
  1652. if ( pbCheckFULLPropsAvailInAndOut != NULL)
  1653. {
  1654. *pbCheckFULLPropsAvailInAndOut = TRUE;
  1655. SAFEIRELEASE(pIEmbedObj2);
  1656. break;
  1657. }
  1658. _bstr_t bstrDesc;
  1659. hr = GetDescOfObject(pIEmbedObj2, bstrDesc,
  1660. rParsedInfo);
  1661. ONFAILTHROWERROR(hr);
  1662. PROPERTYDETAILS pdPropDet;
  1663. if (vtPropertyDerivation.vt == VT_BSTR)
  1664. pdPropDet.Derivation =
  1665. vtPropertyDerivation.bstrVal;
  1666. else
  1667. pdPropDet.Derivation = _bstr_t(TOKEN_NA);
  1668. if (bstrDesc != _bstr_t(""))
  1669. pdPropDet.Description = bstrDesc;
  1670. else
  1671. pdPropDet.Description = _bstr_t(TOKEN_NA);
  1672. hr = GetQualifiers(pIEmbedObj2, pdPropDet,
  1673. rParsedInfo);
  1674. if (!pdPropDet.Type)
  1675. pdPropDet.Type = _bstr_t(TOKEN_NA);
  1676. if (!pdPropDet.Operation)
  1677. pdPropDet.Operation = _bstr_t(TOKEN_NA);
  1678. // Add propertyname to property list in
  1679. // rParsedInfo
  1680. rParsedInfo.GetCmdSwitchesObject().
  1681. AddToPropDetMap(
  1682. vtPropertyName.bstrVal, pdPropDet);
  1683. VARIANTCLEAR(vtPropertyName);
  1684. VARIANTCLEAR(vtPropertyDerivation);
  1685. }
  1686. SAFEIRELEASE(pIEmbedObj2)
  1687. }
  1688. }
  1689. // Release memory held by vtProperties
  1690. VARIANTCLEAR(vtProperties);
  1691. // Free memory held by vtFormatName
  1692. VARIANTCLEAR(vtFormatName);
  1693. // Release pIEmbedObj
  1694. SAFEIRELEASE(pIEmbedObj);
  1695. break;
  1696. }
  1697. // Free memory held by vtFormatName
  1698. VARIANTCLEAR(vtFormatName);
  1699. // Release pIEmbedObj
  1700. SAFEIRELEASE(pIEmbedObj);
  1701. }
  1702. // Release memory held by vtFormats
  1703. VARIANTCLEAR(vtFormats);
  1704. }
  1705. SAFEIRELEASE(pIWbemObj);
  1706. }
  1707. catch(_com_error& e)
  1708. {
  1709. SAFEIRELEASE(pIWbemObj);
  1710. SAFEIRELEASE(pIEmbedObj);
  1711. SAFEIRELEASE(pIEmbedObj2);
  1712. VARIANTCLEAR(vtFormats);
  1713. VARIANTCLEAR(vtFormatName);
  1714. VARIANTCLEAR(vtProperties);
  1715. VARIANTCLEAR(vtPropertyName);
  1716. VARIANTCLEAR(vtPropertyDerivation);
  1717. hr = e.Error();
  1718. rParsedInfo.GetCmdSwitchesObject().SetCOMError(e);
  1719. }
  1720. catch(CHeap_Exception)
  1721. {
  1722. SAFEIRELEASE(pIWbemObj);
  1723. SAFEIRELEASE(pIEmbedObj);
  1724. SAFEIRELEASE(pIEmbedObj2);
  1725. VARIANTCLEAR(vtFormats);
  1726. VARIANTCLEAR(vtFormatName);
  1727. VARIANTCLEAR(vtProperties);
  1728. VARIANTCLEAR(vtPropertyName);
  1729. VARIANTCLEAR(vtPropertyDerivation);
  1730. hr = WBEM_E_OUT_OF_MEMORY;
  1731. _com_issue_error(hr);
  1732. }
  1733. return hr;
  1734. }
  1735. /*----------------------------------------------------------------------------
  1736. Name :GetDescOfObject
  1737. Synopsis :Get the Localized description from alias definition.
  1738. Type :Member Function
  1739. Input parameter(s):
  1740. pIWbemClassObject - IWbemLocator object
  1741. rParsedInfo - The parsed info from command line input.
  1742. Output parameter(s):
  1743. bstrDescription - Localized description
  1744. rParsedInfo` - The parsed info from command line input.
  1745. Return Type :HRESULT
  1746. Global Variables :None
  1747. Calling Syntax :GetDescOfObject(pIObject, bstrDescription,
  1748. rParsedInfo)
  1749. Notes :None
  1750. ----------------------------------------------------------------------------*/
  1751. HRESULT CCmdAlias::GetDescOfObject(IWbemClassObject* pIObject,
  1752. _bstr_t& bstrDescription,
  1753. CParsedInfo& rParsedInfo,
  1754. BOOL bLocalizeFlag)
  1755. {
  1756. HRESULT hr = S_OK;
  1757. DWORD dwThreadId = GetCurrentThreadId();
  1758. VARIANT vtDesc, vtRelPath;
  1759. VariantInit(&vtDesc);
  1760. VariantInit(&vtRelPath);
  1761. try
  1762. {
  1763. CHString chsMsg;
  1764. _bstr_t bstrRelPath;
  1765. _bstr_t bstrResult;
  1766. if (!bLocalizeFlag)
  1767. {
  1768. // Get "Description" property.
  1769. hr = pIObject->Get(_bstr_t(L"Description"), 0, &vtDesc, 0, 0);
  1770. if (m_bTrace || m_eloErrLogOpt)
  1771. {
  1772. chsMsg.Format(L"IWbemClassObject::Get(L\"Description\", 0,"
  1773. L"-, 0, 0)");
  1774. GetBstrTFromVariant(vtDesc, bstrResult);
  1775. WMITRACEORERRORLOG(hr, __LINE__, __FILE__, (LPCWSTR)chsMsg,
  1776. dwThreadId, rParsedInfo, m_bTrace,
  1777. 0 ,bstrResult);
  1778. }
  1779. ONFAILTHROWERROR(hr);
  1780. if (vtDesc.vt == VT_BSTR )
  1781. bstrDescription = vtDesc.bstrVal;
  1782. VARIANTCLEAR(vtDesc);
  1783. }
  1784. else // Get the localized description
  1785. {
  1786. // Get the __RELPATH
  1787. hr = pIObject->Get(_bstr_t(L"__RELPATH"), 0, &vtRelPath, 0, 0);
  1788. if (m_bTrace || m_eloErrLogOpt)
  1789. {
  1790. chsMsg.Format(L"IWbemClassObject::Get(L\"__RELPATH\", 0,"
  1791. L"-, 0, 0)");
  1792. GetBstrTFromVariant(vtRelPath, bstrResult);
  1793. WMITRACEORERRORLOG(hr, __LINE__, __FILE__, (LPCWSTR)chsMsg,
  1794. dwThreadId, rParsedInfo, m_bTrace,
  1795. 0, bstrResult);
  1796. }
  1797. ONFAILTHROWERROR(hr);
  1798. if ((vtRelPath.vt != VT_NULL) && (vtRelPath.vt != VT_EMPTY))
  1799. {
  1800. // Get localized description of the property.
  1801. hr = GetLocalizedDesc(vtRelPath.bstrVal,
  1802. bstrDescription, rParsedInfo);
  1803. if(FAILED(hr))
  1804. {
  1805. hr = S_OK;
  1806. WMIFormatMessage(IDS_E_NO_DESC, 0, bstrDescription, NULL);
  1807. }
  1808. }
  1809. VARIANTCLEAR(vtRelPath);
  1810. }
  1811. }
  1812. catch (_com_error& e)
  1813. {
  1814. VARIANTCLEAR(vtRelPath);
  1815. VARIANTCLEAR(vtDesc);
  1816. rParsedInfo.GetCmdSwitchesObject().SetCOMError(e);
  1817. hr = e.Error();
  1818. }
  1819. catch(CHeap_Exception)
  1820. {
  1821. VARIANTCLEAR(vtRelPath);
  1822. VARIANTCLEAR(vtDesc);
  1823. hr = WBEM_E_OUT_OF_MEMORY;
  1824. _com_issue_error(hr);
  1825. }
  1826. return hr;
  1827. }
  1828. /*----------------------------------------------------------------------------
  1829. Name :ObtainTranslateTableEntries
  1830. Synopsis :Obtain the translate table information from the alias
  1831. definition
  1832. Type :Member Function
  1833. Input parameter(s):
  1834. rParsedInfo - The parsed info from command line input.
  1835. Output parameter(s):
  1836. rParsedInfo - The parsed info from command line input.
  1837. Return Type :HRESULT
  1838. Global Variables :None
  1839. Calling Syntax :ObtainTranslateTableEntries(rParsedInfo)
  1840. Notes :None
  1841. ----------------------------------------------------------------------------*/
  1842. BOOL CCmdAlias::ObtainTranslateTableEntries(CParsedInfo& rParsedInfo)
  1843. {
  1844. BOOL bSuccess = TRUE;
  1845. HRESULT hr = S_OK;
  1846. IWbemClassObject *pIWbemObjOfTable = NULL,
  1847. *pIWbemObjOfTblEntry = NULL;
  1848. DWORD dwThreadId = GetCurrentThreadId();
  1849. VARIANT vtTblEntryArr, vtFromValue, vtToValue;
  1850. VariantInit(&vtTblEntryArr);
  1851. VariantInit(&vtFromValue);
  1852. VariantInit(&vtToValue);
  1853. try
  1854. {
  1855. CHString chsMsg;
  1856. _bstr_t bstrResult;
  1857. _bstr_t bstrPath = _bstr_t("MSFT_CliTranslateTable.Name='") +
  1858. _bstr_t(rParsedInfo.GetCmdSwitchesObject().GetTranslateTableName())+
  1859. _bstr_t(L"'");
  1860. hr = m_pIAliasNS->GetObject(bstrPath, 0, NULL,
  1861. &pIWbemObjOfTable, NULL);
  1862. if (m_bTrace || m_eloErrLogOpt)
  1863. {
  1864. chsMsg.Format(L"IWbemServices::GetObject(L\"%s\", 0, NULL, -)",
  1865. (WCHAR*) bstrPath);
  1866. WMITRACEORERRORLOG(hr, __LINE__, __FILE__, (LPCWSTR)chsMsg,
  1867. dwThreadId, rParsedInfo, m_bTrace);
  1868. }
  1869. // do not add ONFAILTHROWERROR(hr) here, as following statement checks
  1870. // for validity
  1871. if ( pIWbemObjOfTable != NULL )
  1872. {
  1873. VariantInit(&vtTblEntryArr);
  1874. hr = pIWbemObjOfTable->Get(_bstr_t(L"Tbl"), 0,
  1875. &vtTblEntryArr, 0, 0 );
  1876. if ( vtTblEntryArr.vt != VT_NULL && vtTblEntryArr.vt != VT_EMPTY )
  1877. {
  1878. LONG lUpper = 0, lLower = 0;
  1879. hr = SafeArrayGetLBound(vtTblEntryArr.parray,
  1880. vtTblEntryArr.parray->cDims,
  1881. &lLower);
  1882. if ( m_eloErrLogOpt )
  1883. {
  1884. chsMsg.Format(L"SafeArrayGetLBound(-, -, -)");
  1885. WMITRACEORERRORLOG(hr, __LINE__, __FILE__,(LPCWSTR)chsMsg,
  1886. dwThreadId, rParsedInfo, FALSE);
  1887. }
  1888. ONFAILTHROWERROR(hr);
  1889. hr = SafeArrayGetUBound(vtTblEntryArr.parray,
  1890. vtTblEntryArr.parray->cDims,
  1891. &lUpper);
  1892. if ( m_eloErrLogOpt )
  1893. {
  1894. chsMsg.Format(L"SafeArrayGetUBound(-, -, -)");
  1895. WMITRACEORERRORLOG(hr, __LINE__, __FILE__,(LPCWSTR)chsMsg,
  1896. dwThreadId, rParsedInfo, FALSE);
  1897. }
  1898. ONFAILTHROWERROR(hr);
  1899. for (LONG lIndex = lLower; lIndex <= lUpper; lIndex++)
  1900. {
  1901. pIWbemObjOfTblEntry = NULL;
  1902. hr = SafeArrayGetElement(vtTblEntryArr.parray,&lIndex,
  1903. &pIWbemObjOfTblEntry);
  1904. if ( m_eloErrLogOpt )
  1905. {
  1906. chsMsg.Format(L"SafeArrayGetElement(-, -, -)");
  1907. WMITRACEORERRORLOG(hr, __LINE__, __FILE__,(LPCWSTR)chsMsg,
  1908. dwThreadId, rParsedInfo, FALSE);
  1909. }
  1910. ONFAILTHROWERROR(hr);
  1911. VariantInit(&vtFromValue);
  1912. VariantInit(&vtToValue);
  1913. hr = pIWbemObjOfTblEntry->Get(_bstr_t(L"FromValue"), 0,
  1914. &vtFromValue, 0, 0 );
  1915. if (m_bTrace || m_eloErrLogOpt)
  1916. {
  1917. chsMsg.Format(L"IWbemClassObject::Get(L\"FromValue\","
  1918. L"0, -, 0, 0)");
  1919. GetBstrTFromVariant(vtFromValue, bstrResult);
  1920. WMITRACEORERRORLOG(hr, __LINE__, __FILE__,
  1921. (LPCWSTR)chsMsg, dwThreadId,
  1922. rParsedInfo, m_bTrace,
  1923. 0, bstrResult);
  1924. }
  1925. ONFAILTHROWERROR(hr);
  1926. hr = pIWbemObjOfTblEntry->Get(_bstr_t(L"ToValue"),
  1927. 0, &vtToValue, 0, 0 );
  1928. if (m_bTrace || m_eloErrLogOpt)
  1929. {
  1930. chsMsg.Format(L"IWbemClassObject::Get(L\"ToValue\", "
  1931. L"0, -, 0, 0)");
  1932. GetBstrTFromVariant(vtToValue, bstrResult);
  1933. WMITRACEORERRORLOG(hr, __LINE__, __FILE__,
  1934. (LPCWSTR)chsMsg, dwThreadId,
  1935. rParsedInfo, m_bTrace,
  1936. 0 , bstrResult);
  1937. }
  1938. ONFAILTHROWERROR(hr);
  1939. rParsedInfo.GetCmdSwitchesObject().
  1940. AddToAlsFrnNmsOrTrnsTblMap(
  1941. _bstr_t(vtFromValue.bstrVal),
  1942. _bstr_t(vtToValue.bstrVal) );
  1943. VARIANTCLEAR(vtFromValue);
  1944. VARIANTCLEAR(vtToValue);
  1945. SAFEIRELEASE(pIWbemObjOfTblEntry);
  1946. }
  1947. }
  1948. else
  1949. bSuccess = FALSE;
  1950. SAFEIRELEASE(pIWbemObjOfTable);
  1951. VARIANTCLEAR(vtTblEntryArr);
  1952. }
  1953. else
  1954. bSuccess = FALSE;
  1955. }
  1956. catch(_com_error& e)
  1957. {
  1958. rParsedInfo.GetCmdSwitchesObject().SetCOMError(e);
  1959. bSuccess = FALSE;
  1960. SAFEIRELEASE(pIWbemObjOfTable);
  1961. VARIANTCLEAR(vtTblEntryArr);
  1962. VARIANTCLEAR(vtFromValue);
  1963. VARIANTCLEAR(vtToValue);
  1964. SAFEIRELEASE(pIWbemObjOfTblEntry);
  1965. }
  1966. catch(CHeap_Exception)
  1967. {
  1968. bSuccess = FALSE;
  1969. SAFEIRELEASE(pIWbemObjOfTable);
  1970. VARIANTCLEAR(vtTblEntryArr);
  1971. VARIANTCLEAR(vtFromValue);
  1972. VARIANTCLEAR(vtToValue);
  1973. SAFEIRELEASE(pIWbemObjOfTblEntry);
  1974. hr = WBEM_E_OUT_OF_MEMORY;
  1975. _com_issue_error(hr);
  1976. }
  1977. return bSuccess;
  1978. }
  1979. /*----------------------------------------------------------------------------
  1980. Name :PopulateAliasFormatMap
  1981. Synopsis :populate the alias format map with the available formats
  1982. Type :Member Function
  1983. Input parameter(s):
  1984. rParsedInfo - reference to CParsedInfo class object
  1985. Output parameter(s):
  1986. rParsedInfo - reference to CParsedInfo class object
  1987. Return Type :HRESULT
  1988. Global Variables :None
  1989. Calling Syntax :PopulateAliasFormatMap(rParsedInfo)
  1990. Notes :None
  1991. ----------------------------------------------------------------------------*/
  1992. HRESULT CCmdAlias::PopulateAliasFormatMap(CParsedInfo& rParsedInfo)
  1993. {
  1994. // variables being used in this function.
  1995. HRESULT hr = S_OK;
  1996. IWbemClassObject *pIWbemObj = NULL;
  1997. IWbemClassObject *pIEmbedObj = NULL;
  1998. VARIANT vtFormats, vtFormatName;
  1999. // Initializing all Variants variables being used in this function.
  2000. VariantInit(&vtFormats);
  2001. VariantInit(&vtFormatName);
  2002. DWORD dwThreadId = GetCurrentThreadId();
  2003. try
  2004. {
  2005. CHString chsMsg;
  2006. _bstr_t bstrResult;
  2007. _bstr_t bstrPath = _bstr_t("MSFT_CliAlias.FriendlyName='") +
  2008. _bstr_t(rParsedInfo.GetCmdSwitchesObject().GetAliasName()) +
  2009. _bstr_t(L"'");
  2010. // Get alias object
  2011. hr = m_pIAliasNS->GetObject(bstrPath, 0, NULL, &pIWbemObj, NULL);
  2012. if (m_bTrace || m_eloErrLogOpt)
  2013. {
  2014. chsMsg.Format(L"IWbemServices::GetObject(L\"%s\", 0, NULL, -)",
  2015. (WCHAR*) bstrPath);
  2016. WMITRACEORERRORLOG(hr, __LINE__, __FILE__, (LPCWSTR)chsMsg,
  2017. dwThreadId, rParsedInfo, m_bTrace);
  2018. }
  2019. ONFAILTHROWERROR(hr);
  2020. // Get Formats array property of alias object
  2021. hr = pIWbemObj->Get(_bstr_t(L"Formats"), 0, &vtFormats, 0, 0);
  2022. if (m_bTrace || m_eloErrLogOpt)
  2023. {
  2024. chsMsg.Format(L"IWbemClassObject::Get(L\"Formats\", 0,"
  2025. L"-, 0, 0)");
  2026. GetBstrTFromVariant(vtFormats, bstrResult);
  2027. WMITRACEORERRORLOG(hr, __LINE__, __FILE__, (LPCWSTR)chsMsg,
  2028. dwThreadId, rParsedInfo, m_bTrace,
  2029. 0, bstrResult);
  2030. }
  2031. ONFAILTHROWERROR(hr);
  2032. if ( vtFormats.vt != VT_NULL && vtFormats.vt != VT_EMPTY )
  2033. {
  2034. // Get lower and upper bounds of Formats array
  2035. LONG lUpper = 0, lLower = 0;
  2036. hr = SafeArrayGetLBound(vtFormats.parray, vtFormats.parray->cDims,
  2037. &lLower);
  2038. if ( m_eloErrLogOpt )
  2039. {
  2040. chsMsg.Format(L"SafeArrayGetLBound(-, -, -)");
  2041. WMITRACEORERRORLOG(hr, __LINE__, __FILE__, (LPCWSTR)chsMsg,
  2042. dwThreadId, rParsedInfo, FALSE);
  2043. }
  2044. ONFAILTHROWERROR(hr);
  2045. hr = SafeArrayGetUBound(vtFormats.parray, vtFormats.parray->cDims,
  2046. &lUpper);
  2047. if ( m_eloErrLogOpt )
  2048. {
  2049. chsMsg.Format(L"SafeArrayGetUBound(-, -, -)");
  2050. WMITRACEORERRORLOG(hr, __LINE__, __FILE__, (LPCWSTR)chsMsg,
  2051. dwThreadId, rParsedInfo, FALSE);
  2052. }
  2053. ONFAILTHROWERROR(hr);
  2054. // Iterate through the Formats array property
  2055. for (LONG lIndex = lLower; lIndex <= lUpper; lIndex++)
  2056. {
  2057. VariantInit(&vtFormatName);
  2058. // Get this property.
  2059. hr =SafeArrayGetElement(vtFormats.parray,&lIndex,&pIEmbedObj);
  2060. if ( m_eloErrLogOpt )
  2061. {
  2062. chsMsg.Format(L"SafeArrayGetElement(-, -, -)");
  2063. WMITRACEORERRORLOG(hr, __LINE__, __FILE__,(LPCWSTR)chsMsg,
  2064. dwThreadId, rParsedInfo, FALSE);
  2065. }
  2066. ONFAILTHROWERROR(hr);
  2067. hr = pIEmbedObj->Get(_bstr_t(L"Name"),0,&vtFormatName,0,0);
  2068. if (m_bTrace || m_eloErrLogOpt)
  2069. {
  2070. chsMsg.Format(L"IWbemClassObject::Get(L\"Name\", 0,"
  2071. L"-, 0, 0)");
  2072. GetBstrTFromVariant(vtFormatName, bstrResult);
  2073. WMITRACEORERRORLOG(hr, __LINE__, __FILE__,(LPCWSTR)chsMsg,
  2074. dwThreadId, rParsedInfo, m_bTrace,
  2075. 0, bstrResult);
  2076. }
  2077. ONFAILTHROWERROR(hr);
  2078. // To obtain properties from alias associated with the format
  2079. rParsedInfo.GetCmdSwitchesObject().SetListFormat(
  2080. _bstr_t(vtFormatName.bstrVal));
  2081. if ( ObtainAliasFormat(rParsedInfo) == TRUE )
  2082. {
  2083. CHARVECTOR cvProps = rParsedInfo.GetCmdSwitchesObject().
  2084. GetPropertyList();
  2085. CHARVECTOR::iterator cvIterator;
  2086. BSTRVECTOR bvProps;
  2087. for ( cvIterator = cvProps.begin();
  2088. cvIterator != cvProps.end();
  2089. cvIterator++ )
  2090. {
  2091. bvProps.push_back(_bstr_t(*cvIterator));
  2092. }
  2093. //Add format name to format list in rParsedInfo
  2094. rParsedInfo.GetCmdSwitchesObject().
  2095. AddToAliasFormatDetMap(vtFormatName.bstrVal, bvProps);
  2096. rParsedInfo.GetCmdSwitchesObject().ClearPropertyList();
  2097. }
  2098. SAFEIRELEASE(pIEmbedObj);
  2099. }
  2100. // Release memory held by vtFormats
  2101. VARIANTCLEAR(vtFormats);
  2102. }
  2103. // Release pIWbem object
  2104. SAFEIRELEASE(pIWbemObj);
  2105. }
  2106. catch(_com_error& e)
  2107. {
  2108. SAFEIRELEASE(pIEmbedObj);
  2109. SAFEIRELEASE(pIWbemObj);
  2110. VARIANTCLEAR(vtFormats);
  2111. VARIANTCLEAR(vtFormatName);
  2112. rParsedInfo.GetCmdSwitchesObject().SetCOMError(e);
  2113. hr = e.Error();
  2114. }
  2115. catch(CHeap_Exception)
  2116. {
  2117. SAFEIRELEASE(pIEmbedObj);
  2118. SAFEIRELEASE(pIWbemObj);
  2119. VARIANTCLEAR(vtFormats);
  2120. VARIANTCLEAR(vtFormatName);
  2121. hr = WBEM_E_OUT_OF_MEMORY;
  2122. _com_issue_error(hr);
  2123. }
  2124. return hr;
  2125. }
  2126. /*----------------------------------------------------------------------------
  2127. Name :ObtainTranslateTables
  2128. Synopsis :Obtain the information about translate tables available
  2129. Type :Member Function
  2130. Input parameter(s):
  2131. rParsedInfo - reference to CParsedInfo class object
  2132. Output parameter(s):
  2133. rParsedInfo - reference to CParsedInfo class object
  2134. Return Type :HRESULT
  2135. Global Variables :None
  2136. Calling Syntax :ObtainTranslateTables(rParsedInfo)
  2137. Notes :None
  2138. ----------------------------------------------------------------------------*/
  2139. HRESULT CCmdAlias::ObtainTranslateTables(CParsedInfo& rParsedInfo)
  2140. {
  2141. // variables being used in this function.
  2142. HRESULT hr = S_OK;
  2143. IEnumWbemClassObject *pIEnumObj = NULL;
  2144. IWbemClassObject *pIWbemObj = NULL;
  2145. DWORD dwThreadId = GetCurrentThreadId();
  2146. VARIANT vtName;
  2147. VariantInit(&vtName);
  2148. try
  2149. {
  2150. CHString chsMsg;
  2151. _bstr_t bstrResult;
  2152. // Get alias object
  2153. hr = m_pIAliasNS->ExecQuery(_bstr_t(L"WQL"),
  2154. _bstr_t(L"SELECT * FROM MSFT_CliTranslateTable"),
  2155. WBEM_FLAG_FORWARD_ONLY|
  2156. WBEM_FLAG_RETURN_IMMEDIATELY, NULL, &pIEnumObj);
  2157. if (m_bTrace || m_eloErrLogOpt)
  2158. {
  2159. chsMsg.Format(L"IWbemServices::ExecQuery(L\"WQL\","
  2160. L"L\"SELECT * FROM MSFT_CliTranslateTable\","
  2161. L"WBEM_FLAG_FORWARD_ONLY|WBEM_FLAG_RETURN_IMMEDIATELY,"
  2162. L"NULL, -)");
  2163. WMITRACEORERRORLOG(hr, __LINE__, __FILE__, (LPCWSTR)chsMsg,
  2164. dwThreadId, rParsedInfo, m_bTrace);
  2165. }
  2166. ONFAILTHROWERROR(hr);
  2167. // Set the security
  2168. hr = SetSecurity(pIEnumObj, NULL, NULL, NULL, NULL,
  2169. rParsedInfo.GetGlblSwitchesObject().GetAuthenticationLevel(),
  2170. rParsedInfo.GetGlblSwitchesObject().GetImpersonationLevel());
  2171. if (m_bTrace || m_eloErrLogOpt)
  2172. {
  2173. chsMsg.Format(
  2174. L"CoSetProxyBlanket(-, RPC_C_AUTHN_WINNT, RPC_C_AUTHZ_NONE,"
  2175. L"NULL, %d, %d, -, EOAC_NONE)",
  2176. rParsedInfo.GetGlblSwitchesObject().GetAuthenticationLevel(),
  2177. rParsedInfo.GetGlblSwitchesObject().GetImpersonationLevel());
  2178. WMITRACEORERRORLOG(hr, __LINE__, __FILE__, (LPCWSTR)chsMsg,
  2179. dwThreadId, rParsedInfo, m_bTrace);
  2180. }
  2181. ONFAILTHROWERROR(hr);
  2182. ULONG ulReturned = 0;
  2183. hr=pIEnumObj->Next(WBEM_INFINITE,1,&pIWbemObj,&ulReturned);
  2184. if (m_bTrace || m_eloErrLogOpt)
  2185. {
  2186. chsMsg.Format(L"IEnumWbemClassObject->Next"
  2187. L"(WBEM_INFINITE, 1, -, -)");
  2188. WMITRACEORERRORLOG(hr, __LINE__, __FILE__, (LPCWSTR)chsMsg,
  2189. dwThreadId, rParsedInfo, m_bTrace);
  2190. }
  2191. ONFAILTHROWERROR(hr);
  2192. // Obtain the object starting at the current position in the
  2193. // enumeration and loop through the instance list.
  2194. while(ulReturned == 1)
  2195. {
  2196. VariantInit(&vtName);
  2197. // Gets "FriendlyName" array property of alias object
  2198. hr = pIWbemObj->Get(_bstr_t(L"Name"), 0, &vtName, 0, 0);
  2199. if (m_bTrace || m_eloErrLogOpt)
  2200. {
  2201. chsMsg.Format(L"IWbemClassObject::Get(L\"Name\", 0,"
  2202. L"-, 0, 0)");
  2203. GetBstrTFromVariant(vtName, bstrResult);
  2204. WMITRACEORERRORLOG(hr, __LINE__, __FILE__, (LPCWSTR)chsMsg,
  2205. dwThreadId, rParsedInfo, m_bTrace,
  2206. 0, bstrResult);
  2207. }
  2208. ONFAILTHROWERROR(hr);
  2209. if (vtName.vt != VT_NULL && vtName.vt != VT_EMPTY)
  2210. {
  2211. rParsedInfo.GetCmdSwitchesObject().
  2212. AddToTrnsTablesList(vtName.bstrVal);
  2213. }
  2214. VARIANTCLEAR(vtName);
  2215. SAFEIRELEASE(pIWbemObj);
  2216. // Move to next instance in the enumeration.
  2217. hr = pIEnumObj->Next(WBEM_INFINITE, 1, &pIWbemObj, &ulReturned);
  2218. if (m_bTrace || m_eloErrLogOpt)
  2219. {
  2220. chsMsg.Format(
  2221. L"IEnumWbemClassObject->Next(WBEM_INFINITE, 1, -, -)");
  2222. WMITRACEORERRORLOG(hr, __LINE__, __FILE__, (LPCWSTR)chsMsg,
  2223. dwThreadId, rParsedInfo, m_bTrace);
  2224. }
  2225. ONFAILTHROWERROR(hr);
  2226. }
  2227. SAFEIRELEASE(pIEnumObj);
  2228. }
  2229. catch(_com_error& e)
  2230. {
  2231. SAFEIRELEASE(pIEnumObj);
  2232. SAFEIRELEASE(pIWbemObj);
  2233. VARIANTCLEAR(vtName);
  2234. rParsedInfo.GetCmdSwitchesObject().SetCOMError(e);
  2235. hr = e.Error();
  2236. }
  2237. catch(CHeap_Exception)
  2238. {
  2239. SAFEIRELEASE(pIEnumObj);
  2240. SAFEIRELEASE(pIWbemObj);
  2241. VARIANTCLEAR(vtName);
  2242. hr = WBEM_E_OUT_OF_MEMORY;
  2243. _com_issue_error(hr);
  2244. }
  2245. return hr;
  2246. }
  2247. /*----------------------------------------------------------------------------
  2248. Name :ConnectToLocalizedNS
  2249. Synopsis :This function connects to localized WMI namespace
  2250. Type :Member Function
  2251. Input parameter(s):
  2252. rParsedInfo - reference to CParsedInfo class object.
  2253. pIWbemLocator- IWbemLocator object for connecting to WMI.
  2254. Output parameter(s):
  2255. rParsedInfo - reference to CParsedInfo class object.
  2256. Return Type :HRESULT
  2257. Global Variables :None
  2258. Calling Syntax :ConnectToLocalizedNS(rParsedInfo,pIWbemLocator)
  2259. Notes :None
  2260. ----------------------------------------------------------------------------*/
  2261. HRESULT CCmdAlias::ConnectToLocalizedNS(CParsedInfo& rParsedInfo,
  2262. IWbemLocator* pIWbemLocator)
  2263. {
  2264. DWORD dwThreadId = GetCurrentThreadId();
  2265. HRESULT hr = S_OK;
  2266. // If the /LOCALE value has been changed since last invocation
  2267. if (rParsedInfo.GetGlblSwitchesObject().GetLocaleFlag())
  2268. {
  2269. SAFEIRELEASE(m_pILocalizedNS);
  2270. try
  2271. {
  2272. CHString chsMsg;
  2273. _bstr_t bstrNS = _bstr_t(rParsedInfo.GetGlblSwitchesObject().
  2274. GetRole())
  2275. + _bstr_t(L"\\")
  2276. + _bstr_t(rParsedInfo.GetGlblSwitchesObject().
  2277. GetLocale());
  2278. // Connect to the specified namespace of Windows Management on the
  2279. // local computer using the locator object.
  2280. hr = Connect(pIWbemLocator, &m_pILocalizedNS,
  2281. bstrNS, NULL, NULL,
  2282. _bstr_t(rParsedInfo.GetGlblSwitchesObject().
  2283. GetLocale()), rParsedInfo);
  2284. if(FAILED(hr)){
  2285. TCHAR msdeflocale[] = _T("ms_409");
  2286. if (m_bTrace || m_eloErrLogOpt)
  2287. {
  2288. chsMsg.Format(
  2289. L"IWbemLocator::ConnectServer(L\"%s not found. Connecting to ms_409\", NULL, "
  2290. L"NULL, L\"%s\", 0L, L\"%s\", NULL, -)",
  2291. (WCHAR*) bstrNS,
  2292. rParsedInfo.GetGlblSwitchesObject().GetLocale(),
  2293. (rParsedInfo.GetAuthorityPrinciple()) ?
  2294. rParsedInfo.GetAuthorityPrinciple() : L"<null>");
  2295. WMITRACEORERRORLOG(hr, __LINE__, __FILE__, (LPCWSTR)chsMsg,
  2296. dwThreadId, rParsedInfo, m_bTrace);
  2297. }
  2298. rParsedInfo.GetGlblSwitchesObject().SetLocale(msdeflocale);
  2299. _bstr_t bstrNS = _bstr_t(rParsedInfo.GetGlblSwitchesObject().
  2300. GetRole())
  2301. + _bstr_t(L"\\")
  2302. + _bstr_t(rParsedInfo.GetGlblSwitchesObject().
  2303. GetLocale());
  2304. // Connect to the specified namespace of Windows Management on the
  2305. // local computer using the locator object.
  2306. hr = Connect(pIWbemLocator, &m_pILocalizedNS,
  2307. bstrNS, NULL, NULL,
  2308. _bstr_t(rParsedInfo.GetGlblSwitchesObject().
  2309. GetLocale()), rParsedInfo);
  2310. }
  2311. // If /TRACE is ON
  2312. if (m_bTrace || m_eloErrLogOpt)
  2313. {
  2314. chsMsg.Format(
  2315. L"IWbemLocator::ConnectServer(L\"%s\", NULL, "
  2316. L"NULL, L\"%s\", 0L, L\"%s\", NULL, -)",
  2317. (WCHAR*) bstrNS,
  2318. rParsedInfo.GetGlblSwitchesObject().GetLocale(),
  2319. (rParsedInfo.GetAuthorityPrinciple()) ?
  2320. rParsedInfo.GetAuthorityPrinciple() : L"<null>");
  2321. WMITRACEORERRORLOG(hr, __LINE__, __FILE__, (LPCWSTR)chsMsg,
  2322. dwThreadId, rParsedInfo, m_bTrace);
  2323. }
  2324. ONFAILTHROWERROR(hr);
  2325. // If /TRACE is ON
  2326. if (m_bTrace || m_eloErrLogOpt)
  2327. {
  2328. chsMsg.Format(
  2329. L"CoSetProxyBlanket(-, RPC_C_AUTHN_WINNT, "
  2330. L"RPC_C_AUTHZ_NONE, NULL, %d, %d, -, EOAC_NONE)",
  2331. rParsedInfo.GetGlblSwitchesObject().GetAuthenticationLevel(),
  2332. rParsedInfo.GetGlblSwitchesObject().GetImpersonationLevel());
  2333. WMITRACEORERRORLOG(hr, __LINE__, __FILE__, (LPCWSTR)chsMsg,
  2334. dwThreadId, rParsedInfo, m_bTrace);
  2335. }
  2336. ONFAILTHROWERROR(hr);
  2337. rParsedInfo.GetGlblSwitchesObject().SetLocaleFlag(FALSE);
  2338. }
  2339. catch(_com_error& e)
  2340. {
  2341. // Set the COM error
  2342. rParsedInfo.GetCmdSwitchesObject().SetCOMError(e);
  2343. hr = e.Error();
  2344. }
  2345. catch(CHeap_Exception)
  2346. {
  2347. // Set the COM error
  2348. hr = WBEM_E_OUT_OF_MEMORY;
  2349. _com_issue_error(hr);
  2350. }
  2351. }
  2352. return hr;
  2353. }
  2354. /*----------------------------------------------------------------------------
  2355. Name :GetLocalizedDesc
  2356. Synopsis :This function retrieves the localized description for
  2357. the object with given relative path,
  2358. Type :Member Function
  2359. Input parameter(s):
  2360. bstrRelPath - relativepath of the object for which
  2361. localized description has to be retrieved.
  2362. rParsedInfo - reference to CParsedInfo class object.
  2363. Output parameter(s):
  2364. bstrDesc - localized description
  2365. rParsedInfo - reference to CParsedInfo class object.
  2366. Return Type :HRESULT
  2367. Global Variables :None
  2368. Calling Syntax :GetLocalizedDesc(bstrRelPath, bstrDesc, rParsedInfo)
  2369. Notes :None
  2370. ----------------------------------------------------------------------------*/
  2371. HRESULT CCmdAlias::GetLocalizedDesc(_bstr_t bstrRelPath,
  2372. _bstr_t& bstrDesc,
  2373. CParsedInfo& rParsedInfo)
  2374. {
  2375. HRESULT hr = S_OK;
  2376. IWbemClassObject *pIObject = NULL;
  2377. DWORD dwThreadId = GetCurrentThreadId();
  2378. VARIANT vtDesc, vtTemp;
  2379. VariantInit(&vtDesc);
  2380. VariantInit(&vtTemp);
  2381. try
  2382. {
  2383. CHString chsMsg;
  2384. _bstr_t bstrResult;
  2385. CHString sTemp((WCHAR*)bstrRelPath);
  2386. // Substitue escape characters i.e. replace '\"' with '\\\"'
  2387. SubstituteEscapeChars(sTemp, L"\"");
  2388. // Object path
  2389. _bstr_t bstrPath =
  2390. _bstr_t(L"MSFT_LocalizablePropertyValue.ObjectLocator=\"\",PropertyName=")
  2391. + _bstr_t(L"\"Description\",RelPath=\"")
  2392. + _bstr_t(sTemp) + _bstr_t(L"\"");
  2393. // Retrieve the object
  2394. hr = m_pILocalizedNS->GetObject(bstrPath, 0, NULL, &pIObject, NULL);
  2395. if (m_bTrace || m_eloErrLogOpt)
  2396. {
  2397. chsMsg.Format(
  2398. L"IWbemServices::GetObject(L\"%s\", 0, NULL, -)",
  2399. (WCHAR*) bstrPath);
  2400. WMITRACEORERRORLOG(hr, __LINE__, __FILE__, (LPCWSTR)chsMsg,
  2401. dwThreadId, rParsedInfo, m_bTrace);
  2402. }
  2403. ONFAILTHROWERROR(hr);
  2404. // Get localized description of the property.
  2405. hr = pIObject->Get(_bstr_t(L"Text"), 0, &vtDesc, 0, 0);
  2406. if (m_bTrace || m_eloErrLogOpt)
  2407. {
  2408. chsMsg.Format(L"IWbemClassObject::Get(L\"Text\", 0, -, 0, 0)");
  2409. GetBstrTFromVariant(vtDesc, bstrResult);
  2410. WMITRACEORERRORLOG(hr, __LINE__, __FILE__, (LPCWSTR)chsMsg,
  2411. dwThreadId, rParsedInfo, m_bTrace,
  2412. 0, bstrResult);
  2413. }
  2414. ONFAILTHROWERROR(hr);
  2415. if (vtDesc.vt != VT_EMPTY && vtDesc.vt != VT_NULL)
  2416. {
  2417. // Get lower and upper bounds of 'Text' array
  2418. LONG lUpper = 0, lLower = 0;
  2419. hr = SafeArrayGetLBound(vtDesc.parray, vtDesc.parray->cDims,
  2420. &lLower);
  2421. ONFAILTHROWERROR(hr);
  2422. hr = SafeArrayGetUBound(vtDesc.parray, vtDesc.parray->cDims,
  2423. &lUpper);
  2424. ONFAILTHROWERROR(hr);
  2425. // Iterate through the Formats array property
  2426. for (LONG lIndex = lLower; lIndex <= lUpper; lIndex++)
  2427. {
  2428. BSTR bstrTemp = NULL;
  2429. hr = SafeArrayGetElement(vtDesc.parray, &lIndex, &bstrTemp);
  2430. ONFAILTHROWERROR(hr);
  2431. if (bstrTemp)
  2432. bstrDesc += bstrTemp;
  2433. }
  2434. }
  2435. VariantClear(&vtDesc);
  2436. SAFEIRELEASE(pIObject);
  2437. }
  2438. catch (_com_error& e)
  2439. {
  2440. VariantClear(&vtTemp);
  2441. VariantClear(&vtDesc);
  2442. SAFEIRELEASE(pIObject);
  2443. hr = e.Error();
  2444. }
  2445. catch(CHeap_Exception)
  2446. {
  2447. VariantClear(&vtTemp);
  2448. VariantClear(&vtDesc);
  2449. SAFEIRELEASE(pIObject);
  2450. hr = WBEM_E_OUT_OF_MEMORY;
  2451. _com_issue_error(hr);
  2452. }
  2453. return hr;
  2454. }
  2455. /*----------------------------------------------------------------------------
  2456. Name :GetQualifiers
  2457. Synopsis :This function retrieves the qualifiers associated with
  2458. propety/parameter referred by pIWbemClassObject
  2459. Type :Member Function
  2460. Input parameter(s):
  2461. pIWbemClassObject - pointer to IWbemClassObject
  2462. rPropDet - reference to PROPERTYDETAILS object
  2463. rParsedInfo - reference to CParsedInfo class object.
  2464. Output parameter(s):
  2465. rPropDet - reference to PROPERTYDETAILS object
  2466. rParsedInfo - reference to CParsedInfo class object.
  2467. Return Type :HRESULT
  2468. Global Variables :None
  2469. Calling Syntax :GetQualifiers(pIObj, rPropDet, rParsedInfo)
  2470. Notes :None
  2471. ----------------------------------------------------------------------------*/
  2472. HRESULT CCmdAlias::GetQualifiers(IWbemClassObject *pIWbemClassObject,
  2473. PROPERTYDETAILS& rPropDet,
  2474. CParsedInfo& rParsedInfo)
  2475. {
  2476. IWbemClassObject *pIWbemQualObject = NULL;
  2477. HRESULT hr = S_OK;
  2478. DWORD dwThreadId = GetCurrentThreadId();
  2479. VARIANT vtQualifiers, vtQualName, vtQualValues;
  2480. VariantInit(&vtQualifiers);
  2481. VariantInit(&vtQualName);
  2482. VariantInit(&vtQualValues);
  2483. try
  2484. {
  2485. CHString chsMsg;
  2486. _bstr_t bstrResult;
  2487. //Getting the "Qualifiers" property.
  2488. hr=pIWbemClassObject->Get(_bstr_t(L"Qualifiers"), 0,
  2489. &vtQualifiers, 0, 0);
  2490. if (m_bTrace || m_eloErrLogOpt)
  2491. {
  2492. chsMsg.Format(L"IWbemClassObject::Get"
  2493. L"(L\"Qualifiers\", 0, -, 0, 0)");
  2494. GetBstrTFromVariant(vtQualifiers, bstrResult);
  2495. WMITRACEORERRORLOG(hr, __LINE__, __FILE__,
  2496. (LPCWSTR)chsMsg, dwThreadId,
  2497. rParsedInfo, m_bTrace, 0, bstrResult);
  2498. }
  2499. ONFAILTHROWERROR(hr);
  2500. if ( vtQualifiers.vt != VT_NULL && vtQualifiers.vt != VT_EMPTY )
  2501. {
  2502. LONG lLower = 0, lUpper = 0;
  2503. hr = SafeArrayGetLBound(vtQualifiers.parray,
  2504. vtQualifiers.parray->cDims, &lLower);
  2505. if ( m_eloErrLogOpt )
  2506. {
  2507. chsMsg.Format(L"SafeArrayGetLBound(-, -, -)");
  2508. WMITRACEORERRORLOG(hr, __LINE__, __FILE__, (LPCWSTR)chsMsg,
  2509. dwThreadId, rParsedInfo, FALSE);
  2510. }
  2511. ONFAILTHROWERROR(hr);
  2512. hr = SafeArrayGetUBound(vtQualifiers.parray,
  2513. vtQualifiers.parray->cDims, &lUpper);
  2514. if ( m_eloErrLogOpt )
  2515. {
  2516. chsMsg.Format(L"SafeArrayGetUBound(-, -, -)");
  2517. WMITRACEORERRORLOG(hr, __LINE__, __FILE__, (LPCWSTR)chsMsg,
  2518. dwThreadId, rParsedInfo, FALSE);
  2519. }
  2520. ONFAILTHROWERROR(hr);
  2521. // Iterate through the Properties array property
  2522. for(LONG lIndex=lLower; lIndex<=lUpper; lIndex++)
  2523. {
  2524. pIWbemQualObject = NULL;
  2525. // Get this property.
  2526. hr = SafeArrayGetElement(vtQualifiers.parray,
  2527. &lIndex, &pIWbemQualObject);
  2528. if ( m_eloErrLogOpt )
  2529. {
  2530. chsMsg.Format(L"SafeArrayGetElement(-, -, -)");
  2531. WMITRACEORERRORLOG(hr, __LINE__, __FILE__,(LPCWSTR)chsMsg,
  2532. dwThreadId, rParsedInfo, FALSE);
  2533. }
  2534. ONFAILTHROWERROR(hr);
  2535. //Getting the "Name" property
  2536. hr = pIWbemQualObject->Get(_bstr_t(L"Name"), 0,
  2537. &vtQualName,0,0);
  2538. if (m_bTrace || m_eloErrLogOpt)
  2539. {
  2540. chsMsg.Format(L"IWbemClassObject::Get"
  2541. L"(L\"Name\", 0, -, 0, 0)");
  2542. GetBstrTFromVariant(vtQualName, bstrResult);
  2543. WMITRACEORERRORLOG(hr, __LINE__, __FILE__,(LPCWSTR)chsMsg,
  2544. dwThreadId, rParsedInfo, m_bTrace,
  2545. 0, bstrResult);
  2546. }
  2547. ONFAILTHROWERROR(hr);
  2548. //Getting the "QualifierValue" property.
  2549. hr=pIWbemQualObject->Get(_bstr_t(L"QualifierValue"),0,
  2550. &vtQualValues, 0, 0);
  2551. if (m_bTrace || m_eloErrLogOpt)
  2552. {
  2553. chsMsg.Format(L"IWbemClassObject::Get"
  2554. L"(L\"QualifierValue\", 0, -, 0, 0)");
  2555. GetBstrTFromVariant(vtQualValues, bstrResult);
  2556. WMITRACEORERRORLOG(hr, __LINE__, __FILE__,(LPCWSTR)chsMsg,
  2557. dwThreadId, rParsedInfo, m_bTrace,
  2558. 0, bstrResult);
  2559. }
  2560. ONFAILTHROWERROR(hr);
  2561. BSTRVECTOR bvQualValues;
  2562. if ( vtQualValues.vt != VT_NULL &&
  2563. vtQualValues.vt != VT_EMPTY )
  2564. {
  2565. LONG lILower = 0, lIUpper = 0;
  2566. hr = SafeArrayGetLBound(vtQualValues.parray,
  2567. vtQualValues.parray->cDims, &lILower);
  2568. if ( m_eloErrLogOpt )
  2569. {
  2570. chsMsg.Format(L"SafeArrayGetLBound(-, -, -)");
  2571. WMITRACEORERRORLOG(hr, __LINE__, __FILE__,(LPCWSTR)chsMsg,
  2572. dwThreadId, rParsedInfo, FALSE);
  2573. }
  2574. ONFAILTHROWERROR(hr);
  2575. hr = SafeArrayGetUBound(vtQualValues.parray,
  2576. vtQualValues.parray->cDims, &lIUpper);
  2577. if ( m_eloErrLogOpt )
  2578. {
  2579. chsMsg.Format(L"SafeArrayGetUBound(-, -, -)");
  2580. WMITRACEORERRORLOG(hr, __LINE__, __FILE__,
  2581. (LPCWSTR)chsMsg, dwThreadId,
  2582. rParsedInfo, FALSE);
  2583. }
  2584. ONFAILTHROWERROR(hr);
  2585. BOOL bIsType = FALSE;
  2586. BOOL bIsRead = FALSE;
  2587. BOOL bIsWrite = FALSE;
  2588. BOOL bIsIn = FALSE;
  2589. BOOL bIsOut = FALSE;
  2590. if (CompareTokens((WCHAR*)vtQualName.bstrVal,
  2591. _T("CIMTYPE")))
  2592. {
  2593. bIsType = TRUE;
  2594. }
  2595. else if (CompareTokens((WCHAR*)vtQualName.bstrVal,
  2596. _T("read")))
  2597. {
  2598. bIsRead = TRUE;
  2599. }
  2600. else if (CompareTokens((WCHAR*)vtQualName.bstrVal,
  2601. _T("write")))
  2602. {
  2603. bIsWrite = TRUE;
  2604. }
  2605. else if (CompareTokens((WCHAR*)vtQualName.bstrVal,
  2606. _T("In")))
  2607. {
  2608. bIsIn = TRUE;
  2609. }
  2610. else if (CompareTokens((WCHAR*)vtQualName.bstrVal,
  2611. _T("Out")))
  2612. {
  2613. bIsOut = TRUE;
  2614. }
  2615. // Iterate through the Properties array property
  2616. for(LONG lIIndex=lILower; lIIndex<=lIUpper; lIIndex++)
  2617. {
  2618. BSTR bstrQualValue = NULL;
  2619. // Get this property.
  2620. hr = SafeArrayGetElement(vtQualValues.parray,
  2621. &lIIndex, &bstrQualValue);
  2622. if ( m_eloErrLogOpt )
  2623. {
  2624. chsMsg.Format(L"SafeArrayGetElement(-, -, -)");
  2625. WMITRACEORERRORLOG(hr, __LINE__, __FILE__,
  2626. (LPCWSTR)chsMsg, dwThreadId,
  2627. rParsedInfo, FALSE);
  2628. }
  2629. ONFAILTHROWERROR(hr);
  2630. if (bstrQualValue)
  2631. bvQualValues.push_back(bstrQualValue);
  2632. if ( lIIndex == 0 )
  2633. {
  2634. if ( bIsType == TRUE )
  2635. {
  2636. rPropDet.Type = bstrQualValue;
  2637. }
  2638. else if ( bIsRead == TRUE &&
  2639. CompareTokens((WCHAR*)bstrQualValue, _T("true")))
  2640. {
  2641. if (!rPropDet.Operation)
  2642. rPropDet.Operation += _bstr_t("Read");
  2643. else
  2644. rPropDet.Operation += _bstr_t("/Read");
  2645. }
  2646. else if ( bIsWrite == TRUE &&
  2647. CompareTokens((WCHAR*)bstrQualValue, _T("true")))
  2648. {
  2649. if (!rPropDet.Operation)
  2650. rPropDet.Operation += _bstr_t("Write");
  2651. else
  2652. rPropDet.Operation += _bstr_t("/Write");
  2653. }
  2654. else if ( bIsIn == TRUE &&
  2655. CompareTokens((WCHAR*)bstrQualValue, _T("true")))
  2656. {
  2657. rPropDet.InOrOut = INP;
  2658. }
  2659. else if ( bIsOut == TRUE &&
  2660. CompareTokens((WCHAR*)bstrQualValue, _T("true")))
  2661. {
  2662. rPropDet.InOrOut = OUTP;
  2663. }
  2664. }
  2665. }
  2666. VARIANTCLEAR(vtQualValues);
  2667. }
  2668. rPropDet.QualDetMap.insert
  2669. (QUALDETMAP::value_type(vtQualName.bstrVal, bvQualValues));
  2670. VARIANTCLEAR(vtQualName);
  2671. SAFEIRELEASE(pIWbemQualObject);
  2672. }
  2673. VARIANTCLEAR(vtQualifiers);
  2674. }
  2675. }
  2676. catch (_com_error& e)
  2677. {
  2678. VARIANTCLEAR(vtQualValues);
  2679. VARIANTCLEAR(vtQualName);
  2680. VARIANTCLEAR(vtQualifiers);
  2681. SAFEIRELEASE(pIWbemQualObject);
  2682. hr = e.Error();
  2683. // Set the COM error
  2684. rParsedInfo.GetCmdSwitchesObject().SetCOMError(e);
  2685. }
  2686. catch(CHeap_Exception)
  2687. {
  2688. VARIANTCLEAR(vtQualValues);
  2689. VARIANTCLEAR(vtQualName);
  2690. VARIANTCLEAR(vtQualifiers);
  2691. SAFEIRELEASE(pIWbemQualObject);
  2692. hr = WBEM_E_OUT_OF_MEMORY;
  2693. _com_issue_error(hr);
  2694. }
  2695. return hr;
  2696. }
  2697. /*----------------------------------------------------------------------------
  2698. Name :AreMethodsAvailable
  2699. Synopsis :Checks whether method are available with alias or not.
  2700. Type :Member Function
  2701. Input parameter(s):
  2702. rParsedInfo - reference to CParsedInfo class object.
  2703. Output parameter(s):None
  2704. Return Type :BOOL
  2705. Global Variables :None
  2706. Calling Syntax :AreMethodsAvailable(rParsedInfo)
  2707. Notes :None
  2708. ----------------------------------------------------------------------------*/
  2709. BOOL CCmdAlias::AreMethodsAvailable(CParsedInfo& rParsedInfo)
  2710. {
  2711. BOOL bMethAvail = TRUE;
  2712. HRESULT hr = S_OK;
  2713. IWbemClassObject *pIWbemObj = NULL;
  2714. DWORD dwThreadId = GetCurrentThreadId();
  2715. VARIANT vtVerbs;
  2716. VariantInit(&vtVerbs);
  2717. try
  2718. {
  2719. CHString chsMsg;
  2720. _bstr_t bstrResult;
  2721. _bstr_t bstrPath = _bstr_t("MSFT_CliAlias.FriendlyName='") +
  2722. _bstr_t(rParsedInfo.GetCmdSwitchesObject().GetAliasName())+
  2723. _bstr_t(L"'");
  2724. //Retrieving the object from the namespace in m_pIAliasNS
  2725. hr = m_pIAliasNS->GetObject(bstrPath, 0, NULL, &pIWbemObj, NULL);
  2726. if (m_bTrace || m_eloErrLogOpt)
  2727. {
  2728. chsMsg.Format(L"IWbemServices::GetObject(L\"%s\", 0, NULL, -)",
  2729. (WCHAR*) bstrPath);
  2730. WMITRACEORERRORLOG(hr, __LINE__, __FILE__, (LPCWSTR)chsMsg,
  2731. dwThreadId, rParsedInfo, m_bTrace);
  2732. }
  2733. ONFAILTHROWERROR(hr);
  2734. // Get "Verbs" property.
  2735. hr = pIWbemObj->Get(_bstr_t(L"Verbs"), 0, &vtVerbs, 0, 0) ;
  2736. if (m_bTrace || m_eloErrLogOpt)
  2737. {
  2738. chsMsg.Format(L"IWbemClassObject::Get(L\"Verbs\", 0, -, 0, 0)");
  2739. GetBstrTFromVariant(vtVerbs, bstrResult);
  2740. WMITRACEORERRORLOG(hr, __LINE__, __FILE__, (LPCWSTR)chsMsg,
  2741. dwThreadId, rParsedInfo, m_bTrace,
  2742. 0, bstrResult);
  2743. }
  2744. ONFAILTHROWERROR(hr);
  2745. if ( vtVerbs.vt == VT_NULL || vtVerbs.vt == VT_EMPTY )
  2746. bMethAvail = FALSE;
  2747. SAFEIRELEASE(pIWbemObj);
  2748. VARIANTCLEAR(vtVerbs);
  2749. }
  2750. catch(_com_error& e)
  2751. {
  2752. bMethAvail = FALSE;
  2753. SAFEIRELEASE(pIWbemObj);
  2754. VARIANTCLEAR(vtVerbs);
  2755. rParsedInfo.GetCmdSwitchesObject().SetCOMError(e);
  2756. bMethAvail = FALSE;
  2757. }
  2758. catch(CHeap_Exception)
  2759. {
  2760. bMethAvail = FALSE;
  2761. SAFEIRELEASE(pIWbemObj);
  2762. VARIANTCLEAR(vtVerbs);
  2763. bMethAvail = FALSE;
  2764. hr = WBEM_E_OUT_OF_MEMORY;
  2765. _com_issue_error(hr);
  2766. }
  2767. return bMethAvail;
  2768. }